Enable/Disable Synaptics Touchpad on Ubuntu

Nov. 21, 2014

A day working from home brought out another problem the new Thinkpad. I did not have a spare mouse lying around and had to fall back to the flawed Touchpad/Trackpoint mechanism on the new T440. My original idea was to disable Touchpad completely through the x.org conf files and rely on the Trackpoint. But it turns out that while Trackpoint navigation works fine, clicking only works for the left-click. For some strange reason I couldn't get right-click to work on the Touchpad upper button area.
So I could not afford to dispense with the Touchpad altogether. At least not yet. Enabling it back through the x.org conf files would require reboot. Whenever a mouse is not handy I should be able to go back to the Touchpad as the primary pointing device. A mechanism to turn it on/off from shell as and when needed had to be devised.

Well, it turned out that this is pretty easy. Ubuntu came with a tool, xinput, which allows you to do just this. Here's how it works:

$ xinput set-prop <device id> "Device Enabled" 0

Essentially the tool allows setting various properties of the input device identified by the unique id and 'Device Enabled' is the option to enable/disable the device. To find the device id:

$ xinput list

and look for the id against the device 'Synaptics TouchPad'. On my machine it was 13.

A small bit of shell script can help automate this:

#!/bin/bash
declare -i ID
ID=`xinput list | grep -Eo 'Synaptics TouchPad\s*id\=[0-9]{1,2}' | grep -Eo '[0-9]{1,2}'`
xinput set-prop $ID "Device Enabled" 0

You can repeat the above to create another script to enable the device back. Using these two scripts you can toggle the touchpad on and off as and when necessary.

I know ideally I should figure out a solution whereby when the mouse is plugged in the touchpad is automatically turned off. But until then, I think I can live with this.