Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Toggle touchpad on/off (python/linux)
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'])
subprocess.check_call(['synclient', 'touchpadoff=1'])
if __name__ == '__main__':

kdm6389 commented May 1, 2013

File "./", line 5
all_states = subprocess.check_output(['synclient']).split('\n')
IndentationError: expected an indented block

why is this happening in my system/pc

kdm6389 commented May 1, 2013

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 ]

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 ]

The touchpad is currently enabled, so turn it off.

xinput set-prop $tp_id "Device Enabled" 0
echo "Touchpad now off."
echo "tp_toggle: Could not get touchpad status from xinput."
exit 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment