Ubuntu – Command-line program to manage trackpoint speed, sensitivity, etc… without restarting session

driversmousethinkpadtrackpoint

I am on Ubuntu 14.04 and Thinkpad T520. This solution works to set values after a restart, but I would like to be able to set and get the values on the fly.

Note: I already made a bash script to do this after some fruitless research, so I am creating this question in case it helps anyone else.

Best Answer

Below is a bash script I made to set the values on the fly. To use, put the script in ~/bin/trackpoint (user bin) or /usr/bin/trackpoint (global bin) and make it executable.

  • trackpoint <option> to get the value
  • trackpoint <option> <value> to set the value
  • trackpoint --values for a list of all option values
  • trackpoint --help for a list of options (just a list of files in $tp_root).

Tested on Ubuntu 14.04. Calls sudo to write values to file.

#!/bin/bash
# trackpoint
# Gets or sets a trackpoint configuration option
# Example - get sensitivity:
#    trackpoint sensitivity
# Example - set sensitivity to 160:
#    trackpoint sensitivity 160

# tp_root locator command from http://askubuntu.com/a/144185/151944
tp_root=`find /sys/devices/platform/i8042 -name name | xargs grep -Fl TrackPoint | sed 's/\/input\/input[0-9]*\/name$//'`

option=$1
value=$2
me=`basename $0`
fail() { echo "Error: $@" 1>&2; exit 1; }

[ -d ${tp_root} ] || fail "Invalid tp_root: ${tp_root}"

option_list=`find ${tp_root} -maxdepth 1 -type f -printf '%f '`;
[ ${option} ] || fail "please provide an option to set or get. Option must be one of: ${option_list}"
[[ ${option} == *--help*  ]] && { echo -e "Usage: ${me} option_name [value_to_set]\n\nGets or sets a trackpoint option.\n\nTo get a list of all values use:\n   ${me} --values\n\nAvailable options:\n   ${option_list}"; exit 0; }
[[ ${option} == *--values* ]] && { for f in `find ${tp_root} -maxdepth 1 -type f -printf '%f '`; do { echo $f; echo "   $(cat ${tp_root}/${f})"; } done; exit 0; }

file="${tp_root}/${option}"
[ -f ${file} ] || fail "option must be one of: ${option_list}"


[ -z ${value} ] && { cat ${file}; exit 0; }

[ ${value} -gt 255 ] && fail "$option cannot be greater than 255"

echo -n ${value}| sudo tee ${file}

echo ""