Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.