Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- function get_id
- {
- idstr=$(xinput -list | grep "PS/2 Generic Mouse")
- # idstr now contains something like "⎜ ↳ PS/2 Generic Mouse id=13 [slave pointer (2)]"
- # split it into different tokens
- # e.i. "Mouse", "id=13", ...
- # http://stackoverflow.com/questions/918886/how-do-i-split-a-string-on-a-delimiter-in-bash/5257398#5257398
- arr=(${idstr// / })
- for token in "${arr[@]}"
- do
- words=(${token//=/ })
- if [ ${#words[@]} -eq 2 ]; then
- if [ "${words[0]}" = "id" ]; then
- id=${words[1]}
- fi
- fi
- done
- }
- function change_state
- {
- state=$(xinput -list $id | grep "disabled")
- if [[ $state ]]
- then
- xinput set-prop $id "Device Enabled" 1
- else
- xinput set-prop $id "Device Enabled" 0
- fi
- }
- get_id
- if [[ $id ]]; then
- change_state
- fi
Advertisement
Add Comment
Please, Sign In to add comment