SHARE
TWEET

toggle touchpad bash shell script

MarkF2020 May 5th, 2019 (edited) 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # This script does two things:
  3. #
  4. #   1. Find the touchpad device ID & State (enabled or disabled).
  5. #   2. Toggle it.
  6. #
  7. # Run this from your .profile, or your distro's settings->startup.
  8.  
  9. echo 'touchpad.sh: DEBUG: entering'
  10.  
  11. #===================================================
  12. # Find the touchpad device number
  13. MY_TOUCHPAD_ID=$(xinput list | grep -i touchpad | cut -d'=' -f2 | cut -d$'\t' -f1)
  14.  
  15. echo 'touchpad.sh: DEBUG: xinput list (device id):' $MY_TOUCHPAD_ID
  16.  
  17. if [ "$MY_TOUCHPAD_ID" == "" ]; then
  18.     echo 'touchpad.sh: ERROR: Can not identify touch pad device number. Exiting'
  19.     exit
  20. fi
  21.  
  22. #===================================================
  23. # If no parm passed, toggle the *current* state.
  24. if [ "$1" == "" ]; then
  25.  
  26.     echo 'touchpad.sh DEBUG: no arg passed'
  27.    
  28.     # Get current state
  29.     MY_TOUCHPAD_STATE=$(xinput list-props $MY_TOUCHPAD_ID | grep -i "device enabled" | cut  -f3)
  30.  
  31.     echo 'touchpad.sh: DEBUG: device' $MY_TOUCHPAD_ID 'has current state:' $MY_TOUCHPAD_STATE
  32.  
  33.     # Toggle current state
  34.     if [ "$MY_TOUCHPAD_STATE" == "0" ]; then
  35.         MY_TOUCHPAD_STATE="1"
  36.     elif [ "$MY_TOUCHPAD_STATE" == "1" ]; then
  37.         MY_TOUCHPAD_STATE="0"
  38.     else
  39.         echo "touchpad.sh: ERROR: Could not find current touchpad status (to toggle). Setting to enabled."
  40.         MY_TOUCHPAD_STATE="1"
  41.     fi
  42.  
  43. #===================================================
  44. # Else, if *valid* parm was passed. Honor it.
  45. elif [ "$1" != "0" ] && [ "$1" != "1" ]; then
  46.     echo "touchpad.sh: ERROR: Passed argument not 0 or 1. Setting to 1."
  47.     MY_TOUCHPAD_STATE="1"
  48. else
  49.     MY_TOUCHPAD_STATE="$1"
  50. fi
  51.  
  52. echo 'touchpad.sh: DEBUG: changing state to' $MY_TOUCHPAD_STATE
  53.  
  54. #===================================================
  55. # Change current state
  56. xinput set-prop $MY_TOUCHPAD_ID "Device Enabled" $MY_TOUCHPAD_STATE
  57.  
  58. echo 'touchpad.sh: DEBUG: exiting'
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top