Skip to content

Instantly share code, notes, and snippets.

@priyadi
Last active May 13, 2017 20:00
Show Gist options
  • Save priyadi/4efdae818b5f03c53bb27406ee08881d to your computer and use it in GitHub Desktop.
Save priyadi/4efdae818b5f03c53bb27406ee08881d to your computer and use it in GitHub Desktop.
Script to toggle Thinkpad Keyboard+Trackpoint on and off
#!/bin/sh
# inspired from https://askubuntu.com/questions/160945/is-there-a-way-to-disable-a-laptops-internal-keyboard
KEYBOARD="AT Translated Set 2 keyboard"
MOUSE="TPPS/2 IBM TrackPoint"
KEYBOARDMASTER="Virtual core keyboard"
MOUSEMASTER="Virtual core pointer"
ICON=~/bin/keyboard-on.png
ICOFF=~/bin/keyboard-off.png
if [ x"$1" == 'xon' ] ; then
notify-send -i $ICON "Enabling keyboard and Trackpoint..." \ "ON - Keyboard connected!"
xinput reattach "$KEYBOARD" "$KEYBOARDMASTER"
xinput reattach "$MOUSE" "$MOUSEMASTER"
elif [ x"$1" == 'xoff' ] ; then
notify-send -i $ICOFF "Disabling keyboard and Trackpoint..." \ "OFF - Keyboard and Trackpoint disconnected!"
xinput float "$KEYBOARD"
xinput float "$MOUSE"
else
if xinput list --short "$KEYBOARD" | grep -q 'floating slave' ; then
notify-send -i $ICON "Enabling keyboard and Trackpoint..." \ "ON - Keyboard and Trackpoint connected!"
xinput reattach "$KEYBOARD" "$KEYBOARDMASTER"
xinput reattach "$MOUSE" "$MOUSEMASTER"
else
notify-send -i $ICOFF "Disabling keyboard..." \ "OFF - Keyboard and Trackpoint disconnected!"
xinput float "$KEYBOARD"
xinput float "$MOUSE"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment