Monday, February 13, 2012

Toggle Touchpad Input in Linux

I'm using Ubuntu 11.10 Desktop on a laptop. This the bash script I wrote to toggle the touchpad on and off:

#!/bin/bash
# This script toggles the touchpad on and off
# $KEYWORD is the word grep searches with to find the id of the touchpad
# $STATE is the on or off state of the touchpad
# $ID is the xinput identifier number of the touchpad

# If this script does not work for your touchpad, look at
# the output of 'xinput list' to see what keyword to replace
# 'touchpad' with

KEYWORD="touchpad"
ID=$(xinput list | grep -i $KEYWORD | grep -o "id=.." | grep -o "[0-9][0-9]")
STATE=$(xinput list-props $ID | grep "Device Enabled[^:]*:" | grep -o "\<[01$]\>")

if [ "$STATE" == "0" ]
then
xinput set-prop $ID "Device Enabled" 1
else
xinput set-prop $ID "Device Enabled" 0
fi

exit 0