2

I have a ThinkPad Edge E520 and am running Ubuntu 14.04 LTS.

I would like to have an executable file on my desktop which can easily turn on or off my TouchPad and TrackPoint:

xinput list
...
⎜   ↳ TPPS/2 IBM TrackPoint                     id=15   [slave  pointer  (2)]
⎜   ↳ SynPS/2 Synaptics TouchPad                id=13   [slave  pointer  (2)]

Through my own research I have created two files, one to turn it on, and one to turn it off. I cannot, however, figure out how to combine these two programs into one program to turn these input off if they are on, and vice versa. I've been playing around with if statements, but can only get the program to always turn the inputs on or always turn them off.

Here is my program to turn the inputs on:

xinput set-prop 15 "Device Enabled" 1
xinput set-prop 13 "Device Enabled" 1

and the other to turn them off:

xinput set-prop 15 "Device Enabled" 0
xinput set-prop 13 "Device Enabled" 0  

Could anyone help me combine these into a single program?

Thanks in advance :)

4
  • Are if statements possible in bash? Commented Apr 17, 2015 at 0:27
  • Huh. It looks like you can. I'll post an answer, since I can't do the code here. Commented Apr 17, 2015 at 0:29
  • Do you know the condition you need? Like if prop 15 "Device Enabled" 0? Commented Apr 17, 2015 at 0:36
  • Play around with xinput query-state 15/13. That might get you closer to what you need. Commented Apr 17, 2015 at 0:39

4 Answers 4

3

I am using another approach to toggle the touchpad state: synclient. You could as well use your xinput commands instead, but I prefer synclient.

I'm using the following script, assigned to a hotkey, to toggle my touchpad on/off:

#!/bin/bash
if [ -z "$(synclient | grep TouchpadOff | grep 1)" ]; then
    synclient TouchpadOff=1
else
    synclient TouchpadOff=0
fi

How does it work?

When executing synclient without any arguments, it returns a list of all settings and their current state. From this list, the script greps the option "TouchpadOff", which is - who would've guessed it - 1 if the touchpad is off and 0 elsewise.

To check this, I used test's -z switch (following string empty), combined with another grep, which evaluates to true, if the touchpad is off. In this case, it again calls synclient with an argument telling it to set the option to "1", thereby disabling the touchpad.

Elsewise, the script does the opposite and reenables the touchpad.


Note that synclient doesn't store settings permanently, so if you don't do anything else, your toucpad will always be enabled on boot.

1
  • If you combine this with a udev rule, you can automatically turn your touchpad off/on when an external mouse is connected/disconnected, respectively.
    – b_laoshi
    Commented Apr 26, 2017 at 6:28
1

I'm using this script to switch the touchpad status.

#!/bin/bash
id=$(xinput | grep -i "TouchPad" | cut -f 2 | cut -d= -f 2)
status=$(xinput --list-props $id | grep "Device Enabled" | cut -f 3)
if [ $status -eq 1 ]; then
    xinput --disable $id
else
    xinput --enable $id
fi
0

I made a little script that you can try. Run it twice from Terminal to see if it can disable and re-enable device 15. If it works, I'll edit in 13. Test

2
  • Ugh. Nevermind. I messed something up. I need to fix it. Commented Apr 17, 2015 at 1:36
  • What's the current status of this answer? Should the script be added? Did it not work out, and the answer should be deleted? Commented Nov 21, 2017 at 13:56
0

Thanks Seppi!

Your script worked perfectly. I added in one of my original lines to also enable/disable the TrackPoint as well.

if [ -z "$(synclient | grep TouchpadOff | grep 1)" ]; then
    synclient TouchpadOff=1
    xinput set-prop 15 "Device Enabled" 0
else
    synclient TouchpadOff=0
    xinput set-prop 15 "Device Enabled" 1
fi

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .