Trying to debug this script for my system

Brodie Robertson did a YouTube video on how to toggle on/off any input device using xorg xinput. In the video, he used his laptop touchpad as an example. This is exactly what I need to do as my touchpad is VERY sensitive and the keyboard toggle key doesn’t work. This is a known issue with my laptop, a Lenovo Yoga 900-13ISK. I downloaded the script from his GitHub repository and made the appropriate entry in my sxhkdrc following his video. Unfortunately, when I press the assigned key (F6 in my case) nothing changes with the touchpad. Using xinput list I get the following for my touchpad:
Synaptics TM0036-002 id=11
Here is his script:

#!/bin/sh
# Script to toggle my laptops touchpad
#id="$(xinput list | grep -Eo 'Touchpad.*id=[0-9]*' | grep -Eo '[0-9]*')"
mode="$(echo "Synaptics TM3066-002" | xargs -I % xinput --list-props % | grep 'Device Enabled' | grep -Eo ':.*[0|1]' | grep 
-Eo '[0|1]')"

if [ "$mode" -eq "1" ]; then
  xinput set-prop "$id" "Device Enabled" 0 && notify-send "Touchpad" "Touchpad has been disabled"
else
  xinput set-prop "$id" "Device Enabled" 1 && notify-send "Touchpad" "Touchpad has been enabled"
fi

My sxhkdrc entry is:

# Touchpad enable / disable
F6
  ~/.local/bin/toggletouch

I’m hoping someone will help me find out why it isn’t working.

Thanks.

Is the id line supposed to be commented out? Maybe you want something like id="11" based on your xinput list result, or just replace Touchpad in that line with Synaptics and uncomment it (assuming you don’t have any other xinputs that have the word Synaptics).

1 Like

The variable is never set:

The line is commented out.

:smiley: beat me too it @Whyhow

1 Like

I replaced Touchpad with ‘Synaptics’ as you suggested but no change. I’ll try changing the id. I thought the first line of the script was to get the id number which would then be used in the if/else part of the script.

Also, I commented out the first line while troubleshooting before I posted. I just forgot to uncomment it.

Some additional information, when I run the script manually, I get

Usage: grep [OPTION]... PATTERNS [FILE]...
Try 'grep --help' for more information.
./toggletouch: line 7: -Eo: command not found
./toggletouch: line 8: [: : integer expression expected
unable to find device 3066
002
11

Just to make sure I haven’t made any unknown changes to the script, here is the original I just downloaded:

#!/bin/sh
# Script to toggle my laptops touchpad
id="$(xinput list | grep -Eo 'Touchpad.*id=[0-9]*' | grep -Eo '[0-9]*')"
mode="$(echo "$id" | xargs -I % xinput --list-props % | grep 'Device Enabled' | grep -Eo ':.*[0|1]' | grep -Eo '[0|1]')"

if [ "$mode" -eq "1" ]; then
  xinput set-prop "$id" "Device Enabled" 0 && notify-send "Touchpad" "Touchpad has been disabled"
else
  xinput set-prop "$id" "Device Enabled" 1 && notify-send "Touchpad" "Touchpad has been enabled"
fi

when I run this manually:

[kent@neuromancer bin]$ ./toggletouch
./toggletouch: line 6: [: : integer expression expected
unable to find device

One problem seems to be that you added a new line within the line getting mode, which messes up the grep command. Make sure that in your copy of the script there is no new line.
Also, can you post the output of xinput list and of xinput list | grep -Eo 'Synaptics.*id=[0-9]*' | grep -Eo '[0-9]*'?

[kent@neuromancer bin]$ xinput list
⎡ Virtual core pointer                    	id=2	[master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer              	id=4	[slave  pointer  (2)]
⎜   ↳ Logitech Wireless Receiver Mouse        	id=10	[slave  pointer  (2)]
⎜   ↳ Synaptics TM3066-002                    	id=11	[slave  pointer  (2)]
⎜   ↳ ELAN21EF:00 04F3:2200                   	id=12	[slave  pointer  (2)]
⎣ Virtual core keyboard                   	id=3	[master keyboard (2)]
    ↳ Virtual core XTEST keyboard             	id=5	[slave  keyboard (3)]
    ↳ Power Button                            	id=6	[slave  keyboard (3)]
    ↳ Video Bus                               	id=7	[slave  keyboard (3)]
    ↳ Lid Switch                              	id=8	[slave  keyboard (3)]
    ↳ Power Button                            	id=9	[slave  keyboard (3)]
    ↳ Ideapad extra buttons                   	id=13	[slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard            	id=14	[slave  keyboard (3)]
[kent@neuromancer bin]$ xinput list | grep -Eo 'Synaptics.*id=[0-9]*' | grep -Eo '[0-9]*'
3066
002
11

What about
xinput list | grep -Eo 'Synaptics.*id=[0-9]*' | grep -Eo 'id=[0-9*]' | grep -Eo '[0-9]*'
It’s probably not the cleanest solution, but I think it will work.

I really appreciate your help. I wasn’t sure what you meant, so I edited the script

#!/bin/sh
# Script to toggle my laptops touchpad
#id="$(xinput list | grep -Eo 'Touchpad.*id=[0-9]*' | grep -Eo '[0-9]*')"
xinput list | grep -Eo 'Synaptics.*id=[0-9]*' | grep -Eo 'id=[0-9]*'
mode="$(echo "$id" | xargs -I % xinput --list-props % | grep 'Device Enabled' | grep -Eo ':.*[0|1]' | grep -Eo '[0|1]')"

if [ "$mode" -eq "1" ]; then
  xinput set-prop "$id" "Device Enabled" 0 && notify-send "Touchpad" "Touchpad has been disabled"
else
  xinput set-prop "$id" "Device Enabled" 1 && notify-send "Touchpad" "Touchpad has been enabled"
fi
this is what I get:
[kent@neuromancer bin]$ ./toggletouch
id=11
./toggletouch: line 7: [: : integer expression expected
unable to find device

First, just use the command xinput list | grep -Eo 'Synaptics.*id=[0-9]*' | grep -Eo 'id=[0-9*]' | grep -Eo '[0-9]*' in the command line. I think it should get 11 as the output, if not we’ll have to do further adjustments.
If it does get 11, replace the bit in parentheses in the id expression with that command, since that one gets the right id for the touchpad.

The reason your script isn’t working is that the line trying to get the id is getting multiple numbers, only one of which is the id. I think my change to that expression would fix it, but running the command on the command line will check that it gets the right answer.

[kent@neuromancer ~]$ xinput list | grep -Eo 'Synaptics.*id=[0-9]*' | grep -Eo 'id=[0-9*]' | grep -Eo '[0-9]*'
1

Sorry, I had a typo. The * should go outside the square brackets, not inside.
xinput list | grep -Eo 'Synaptics.*id=[0-9]*' | grep -Eo 'id=[0-9]*' | grep -Eo '[0-9]*'

:grinning:

[kent@neuromancer ~]$ xinput list | grep -Eo 'Synaptics.*id=[0-9]*' | grep -Eo 'id=[0-9]*' | grep -Eo '[0-9]*'
11
[kent@neuromancer ~]$

Great!
Now if you put that inside the parentheses in the id line, does your script work?

no. :slightly_frowning_face:

[

kent@neuromancer bin]$ cat toggletouch
#!/bin/sh
# Script to toggle my laptops touchpad
id="$(xinput list | grep -Eo 'Synaptics.*id=[0-9]*' | grep -Eo '[0-9]*')"
mode="$(echo "$id" | xargs -I % xinput --list-props % | grep 'Device Enabled' | grep -Eo ':.*[0|1]' | grep -Eo '[0|1]')"

if [ "$mode" -eq "1" ]; then
  xinput set-prop "$id" "Device Enabled" 0 && notify-send "Touchpad" "Touchpad has been disabled"
else
  xinput set-prop "$id" "Device Enabled" 1 && notify-send "Touchpad" "Touchpad has been enabled"
fi
[kent@neuromancer bin]$ toggletouch
unable to find device 3066
/home/kent/.local/bin/toggletouch: line 6: [: 1
1: integer expression expected
unable to find device 3066
002
11

I’m about ready to just find a way to disable the touchpad and use a mouse. I hate waisting your time.

Just FYI, ‘xinput disable 11’ does work.

I think you copied the wrong expression into the id line
Try

#!/bin/sh
id="$(xinput list | grep -Eo 'Synaptics.*id=[0-9]*' | grep -Eo 'id=[0-9]*' | grep -Eo '[0-9]*')"
mode="$(echo "$id" | xargs -I % xinput --list-props % | grep 'Device Enabled' | grep -Eo ':.*[0|1]' | grep -Eo '[0|1]')"

if [ "$mode" -eq "1" ]; then
  xinput set-prop "$id" "Device Enabled" 0 && notify-send "Touchpad" "Touchpad has been disabled"
else
  xinput set-prop "$id" "Device Enabled" 1 && notify-send "Touchpad" "Touchpad has been enabled"
fi

You need the middle grep statement so you only get the bit of the line with the id number, rather than every number in the line.

[kent@neuromancer bin]$ cat toggletouch
id="$(xinput list | grep -Eo 'Synaptics.*id=[0-9]*' | grep -Eo 'id=[0-9*]' | grep -Eo '[0-9]*')"
mode="$(echo "$id" | xargs -I % xinput --list-props % | grep 'Device Enabled' | grep -Eo ':.*[0|1]' | grep -Eo '[0|1]')"

if [ "$mode" -eq "1" ]; then
  xinput set-prop "$id" "Device Enabled" 0 && notify-send "Touchpad" "Touchpad has been disabled"
else
  xinput set-prop "$id" "Device Enabled" 1 && notify-send "Touchpad" "Touchpad has been enabled"
fi
[kent@neuromancer bin]$ ./toggletouch
unable to find device 1
./toggletouch: line 4: [: : integer expression expected
unable to find device 1
[kent@neuromancer bin]$