Guest User

touchpad-on-off

a guest
Feb 5th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.02 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. function get_id
  4. {
  5.         idstr=$(xinput -list | grep "PS/2 Generic Mouse")
  6.         # idstr now contains something like "⎜ ↳ PS/2 Generic Mouse id=13 [slave pointer (2)]"
  7.  
  8.         # split it into different tokens
  9.         # e.i. "Mouse", "id=13", ...
  10.         # http://stackoverflow.com/questions/918886/how-do-i-split-a-string-on-a-delimiter-in-bash/5257398#5257398
  11.         arr=(${idstr// / })
  12.  
  13.         for token in "${arr[@]}"
  14.         do
  15.                 words=(${token//=/ })
  16.                 if [ ${#words[@]} -eq 2 ]; then
  17.                         if [ "${words[0]}" = "id" ]; then
  18.                                 id=${words[1]}
  19.                         fi
  20.                 fi
  21.         done
  22. }
  23.  
  24. function change_state
  25. {
  26.         state=$(xinput -list $id | grep "disabled")
  27.  
  28.         if [[ $state ]]
  29.         then
  30.                 xinput set-prop $id "Device Enabled" 1
  31.         else
  32.                 xinput set-prop $id "Device Enabled" 0
  33.         fi
  34. }
  35.  
  36. get_id
  37. if [[ $id ]]; then
  38.         change_state
  39. fi
Advertisement
Add Comment
Please, Sign In to add comment