Created
February 21, 2021 07:14
-
-
Save tafaust/bc45a06412c93a8f02ae066b55b59068 to your computer and use it in GitHub Desktop.
Bash script to toggle touchpad state on X server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# set your device name here (can be found through `xinput`) | |
touchpadDevice='SynPS/2 Synaptics TouchPad' | |
if [ ! -z "$1" ]; then | |
# set the device state via argument (must be 0 or 1) | |
devEnabled=$1 | |
else | |
# toggle the device state | |
id=$(xinput --list --id-only "$touchpadDevice") | |
devEnabled=$(xinput --list-props $id | awk '/Device Enabled/{print !$NF}') | |
fi | |
# alter the device state and subsequently print the state via wm dbus | |
if [ -n "$DISPLAY" ] ; then | |
export DISPLAY=:1 | |
export touchpadDevice | |
export devEnabled | |
/usr/bin/su $USER -c '/usr/bin/xinput --set-prop "$touchpadDevice" "Device Enabled" "$devEnabled"' | |
/usr/bin/su $USER /usr/bin/notify-send -t 2000 -i "input-touchpad" "$touchpadDevice" "TouchPad device is $([[ $devEnabled -eq 0 ]] && echo -ne "disabled" || echo -ne "enabled")" | |
else | |
/usr/bin/xinput --set-prop "$touchpadDevice" 'Device Enabled' "$devEnabled" | |
/usr/bin/notify-send -t 2000 -i "input-touchpad" "$touchpadDevice" "TouchPad device is $([[ $devEnabled -eq 0 ]] && echo -ne "disabled" || echo -ne "enabled")" | |
fi | |
unset devEnabled | |
unset touchpadDevice | |
unset id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check https://bbs.archlinux.org/viewtopic.php?id=92896 if you want to call this script via udev rather than manually invocation upon usb mouse plug-in/out.