Skip to content

Instantly share code, notes, and snippets.

@hsandt
Created October 24, 2018 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hsandt/d6008521617fa12fbff45c25f114b439 to your computer and use it in GitHub Desktop.
Save hsandt/d6008521617fa12fbff45c25f114b439 to your computer and use it in GitHub Desktop.
A Python script that toggles the touchpad for Linux via gsettings. Useful when the toggle touchpad function key doesn't work and vendor-specific command lines do not apply to your computer.
#!/usr/bin/python3.6
import sys
import subprocess
gsettings_schema, gsettings_key = "org.gnome.desktop.peripherals.touchpad", "send-events"
def get_touchpad_send_events():
send_events_value = subprocess.check_output(["gsettings", "get", gsettings_schema, gsettings_key])
return send_events_value.strip()
def toggle_touchpad():
# string returned from get is a repr including quotes,
# but string sent with set does not need to have quotes
if get_touchpad_send_events() == b"'enabled'":
newval = 'disabled'
else:
newval = 'enabled'
subprocess.Popen(["gsettings", "set", gsettings_schema, gsettings_key, newval])
print(f"Set {gsettings_schema}:{gsettings_key} to {newval}")
def main():
toggle_touchpad()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment