Skip to content

Instantly share code, notes, and snippets.

@Neoklosch
Created October 31, 2014 11:22
Show Gist options
  • Select an option

  • Save Neoklosch/a6921b66f170c80e8116 to your computer and use it in GitHub Desktop.

Select an option

Save Neoklosch/a6921b66f170c80e8116 to your computer and use it in GitHub Desktop.
Toggle Touchpad on Linux Mint
#!/usr/bin/python
from subprocess import Popen, PIPE
import re
terminal_call = ['xinput', 'list']
regex_pattern = re.compile(r'.+TouchPad.+id=(\d+)')
sec_regex_pattern = re.compile(r'.*Device (Enabled|Disabled).+:\s(\d+)')
pp = Popen(terminal_call, stdout=PIPE)
for ln in pp.stdout:
if regex_pattern.match(ln):
id = regex_pattern.findall(ln)[0]
if id:
props = Popen(['xinput', 'list-props', id], stdout=PIPE)
for propln in props.stdout:
if sec_regex_pattern.match(propln):
status = sec_regex_pattern.findall(propln)[0]
if status[1] == str(1):
Popen(['xinput', '--disable', id])
print "TouchPad disabled"
else:
Popen(['xinput', '--enable', id])
print "TouchPad enabled"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment