Skip to content

Instantly share code, notes, and snippets.

@zeph1e
Last active March 16, 2016 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeph1e/c067a41112da700be2cb to your computer and use it in GitHub Desktop.
Save zeph1e/c067a41112da700be2cb to your computer and use it in GitHub Desktop.
#!/bin/sh
XINPUT="xinput"
TP_KEYWORD="Touchpad"
TP_CMD=
TP_ID=`$XINPUT | grep $TP_KEYWORD | awk -F '=' '{ print $2; }' | awk '{ print $1; }'`
if [ -z "$TP_ID" ]; then
echo "Unable to find touchpad" 1>&2
exit 1
fi
if [ -n "$1" ]; then
case $1 in
on)
TP_CMD="enable"
;;
off)
TP_CMD="disable"
;;
*)
echo "Usage: $0 [on|off]" 1>&2
echo "\ton : Turn on touchpad" 1>&2
echo "\toff : Turn off touchpad" 1>&2
echo "\tWith no argument, it toggles its state" 1>&2
exit 1
;;
esac
else
# toggle
TP_STATE=`$XINPUT list-props $TP_ID | grep "Device Enabled" | awk -F ':' '{ print $2; }'`
if [ -n "$TP_STATE" ]; then
if [ $TP_STATE -eq 0 ]; then
TP_CMD="enable"
else
TP_CMD="disable"
fi
else
echo "Something goes wrong..." 1>&2
exit 1
fi
fi
if $XINPUT $TP_CMD $TP_ID; then
notify-send -i "touchpad_$TP_CMD" -u low "Touchpad "$TP_CMD"d"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment