User Controls

Bash Script to Toggle Trackpad

  1. #1
    aldra JIDF Controlled Opposition
    I put this together last night when I realised lunix acpi didn't recognise my laptop's 'disable trackpad' shortcut (fn+F9) - it uses xinput to detect the device ID and status to enable/disable it. I have it attached to an openbox keybind. Nothing complicated, thought it might be useful to someone else though.


    #!/bin/bash

    # aldra 2018
    # using xinput, find the integrated trackpad and toggle it on/off

    deviceRaw=$(xinput --list|grep -i touchpad|grep -P -o "id=.*\t") # force perl regex as posix apparently doesn't escape tab to \t
    deviceClean=${deviceRaw//[!0-9]/} # retrieve numbers only
    deviceState=$(xinput list-props "$deviceClean" | grep -i enabled | grep -o "[01]$")

    if [ $deviceState == '1' ];then
    xinput --disable "$deviceClean"
    echo "Touchpad on $deviceClean disabled."
    else
    xinput --enable "$deviceClean"
    echo "Touchpad on $deviceClean enabled."
    fi


    I'm aware that there are cleaner ways to do the string manipulation. You can replace 'touchpad' in the deviceRaw line with whatever device you want (xinput --list for a list of them)
    The following users say it would be alright if the author of this post didn't die in a fire!
  2. #2
    benny vader YELLOW GHOST
    this post is here to make OP less lonely.
  3. #3
    aldra JIDF Controlled Opposition
    thank mr skeltal

    I remember there was a bash/shellscript thread somewhere but couldn't find it.

    I'm going through python code now, seems fairly straightforward but enforced whitespace is annoying
  4. #4
    apt Tuskegee Airman
    The author of this post has returned to nothingness
  5. #5
    SBTlauien African Astronaut
    Here is one that I made a while back that uses Pythons App Indicator. If you'd like to just swich it rather than running the command.

    https://github.com/SBTlauien/Toucher
  6. #6
    Sophie Pedophile Tech Support
    Originally posted by apt I think I made a scripting thread years ago before the board migration. Not sure those old posts made it over.

    Yee, i remember. It should be on the forum still. Search for a string you know for sure was in the post and the NiS' search function will take you there.
Jump to Top