bashubuntutrackpad

How to set a toggle on linux (True or False) bash command?


I currently assigned my thinkvantage button to turn off tap to click on my trackpad, but I'd like to convert it to a toggle on/off switch.

For the moment, this is the bash command I use to turn it off (or on with CTRL):

gsettings set org.gnome.settings-daemon.peripherals.touchpad tap-to-click true
gsettings set org.gnome.settings-daemon.peripherals.touchpad tap-to-click false

In other words, ho do I turn this into a conditional toggle switch bash statement?


Solution

  • Presumably something like this:

    #!/bin/bash
    class=org.gnome.settings-daemon.peripherals.touchpad
    name=tap-to-click
    status=$(gsettings get "$class" "$name")
    status=${status,,} # normalize to lower case; this is a modern bash extension
    if [[ $status = true ]]; then
      new_status=false
    else
      new_status=true
    fi
    gsettings set "$class" "$name" "$new_status"
    

    Breaking it down into pieces:

    Note that whitespace is important in bash! foo = bar, foo= bar and foo=bar are completely different statements, and all three of them do different things from the other two. Be sure to be cognizant of the differences in copying from this example.