Created
November 3, 2011 14:37
-
-
Save hjwp/1336648 to your computer and use it in GitHub Desktop.
Toggle touchpad on/off (python/linux)
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
#!/usr/bin/python2.7 | |
import subprocess | |
def touchpad_currently_off(): | |
all_states = subprocess.check_output(['synclient']).split('\n') | |
off_state = next((s for s in all_states if 'touchpadoff' in s.lower()), None) | |
return '1' in off_state | |
def main(): | |
if touchpad_currently_off(): | |
subprocess.check_call(['synclient', 'touchpadoff=0']) | |
else: | |
subprocess.check_call(['synclient', 'touchpadoff=1']) | |
if __name__ == '__main__': | |
main() |
but this is working without python simply bash
Get the id number of the touchpad.
tp_id=xinput list | grep -i touchpad | awk '{ print $6 }' | sed 's/id=//'
Find out whether the touchpad is enabled or not.
tp_enabled=xinput list-props $tp_id | grep Device\ Enabled | awk '{ print $4 }'
if [ $tp_enabled = 0 ]
then
The touchpad is currently disabled, so turn it on.
xinput set-prop $tp_id "Device Enabled" 1
echo "Touchpad now on."
elif [ $tp_enabled = 1 ]
then
The touchpad is currently enabled, so turn it off.
xinput set-prop $tp_id "Device Enabled" 0
echo "Touchpad now off."
else
echo "tp_toggle: Could not get touchpad status from xinput."
exit 1
fi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
File "./toggle_touchpad.py", line 5
all_states = subprocess.check_output(['synclient']).split('\n')
^
IndentationError: expected an indented block
$
why is this happening in my system/pc