Skip to content

Instantly share code, notes, and snippets.

@agirorn
Last active July 6, 2017 10:23
Show Gist options
  • Save agirorn/e29ae00c746b88f1a965fbcc608c104b to your computer and use it in GitHub Desktop.
Save agirorn/e29ae00c746b88f1a965fbcc608c104b to your computer and use it in GitHub Desktop.
Disable or enable the TrackPad on an IBM T450 laptop for Ubuntu.
#!/usr/bin/env bash
showHelp() {
cat <<HELP
$0 [OPTIONS]
Enable or Disable the trackpad on T450 on Ubuntu.
Options:
-h, --help Print help screen
-e, --enable Enable track-pad
-d, --disable Disable track-pad
HELP
}
DEVISES=(
"IBM TrackPoint"
"Synaptics TouchPad"
)
id_of() {
xinput list | grep "$1" | tr " " "X" | tr "=" " " | awk '{print $3}'
}
enable() {
xinput set-prop "$(id_of "$1")" "Device Enabled" 1
}
disable() {
xinput set-prop "$(id_of "$1")" "Device Enabled" 0
}
isEnabledString() {
if xinput list-props "$(id_of "$1")" | grep "Device Enabled" | grep --quiet "0"; then
echo "disable"
else
echo "enabled"
fi
}
list() {
echo "$1: $(isEnabledString "$1")"
}
enableDevises() {
for device in "${DEVISES[@]}"
do
enable "$device"
done
listDevises
}
disableDevises() {
for device in "${DEVISES[@]}"
do
disable "$device"
done
listDevises
}
listDevises() {
for device in "${DEVISES[@]}"
do
list "$device"
done
}
if [ -z "${1+x}" ]; then
showHelp
elif [ "$1" == "--enable" ] || [ "$1" == "-e" ]; then
enableDevises
elif [ "$1" == "--disable" ] || [ "$1" == "-d" ]; then
disableDevises
else
showHelp
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment