#!/usr/bin/env bash
## Get the touchpad id. The -P means perl regular expressions (for \K)
## the -i makes it case insensitive (better portability) and the -o
## means print only the matched portion. The \K discards anything matched
## before it so this command will print the numeric id only.
TID=$(xinput list | grep -iPo 'touchpad.*id=\K\d+')
## Run every second
while :
do
## Disable the touchpad if there is a mouse connected
## and enable it if there is none.
xinput list | grep -iq mouse && xinput disable "$TID" || xinput enable "$TID"
## wait one second to avoind spamming your CPU
sleep 1
done
“Now, save the script as ~/touchpad.sh, make it executable (chmod +x ~/touchpad.sh) and add it to your GUI session startup programs.”
I accomplished the three steps above, rebooted and the Touchpad is still active. I tried just running the script, but that has no effect either.
I’m now officially lost and need help. Any body have a clue?
Ahh yup! I went through the same tortured process to then after learning to live in torment stumbled upon the simple hardware fix. For me it was staring at my keyboard looking for something else and … hmmmm wonder what THAT button’s for.
Fred, I tried several scripts that just did not work. Then, this morning, I searched the forum and found this post -
Unfortunately, he posted in screenshots. I took the liberty of transcribing the touchpadonoff script. It works but I suppose that a function key switch is really a lot easier.
#!/bin/bash
# TouchOnOff, version 1.0, December 2017, Author: GFP
# Adaptation of the KbOnOff bash script
Icon=/usr/share/icons/gnome/256x256/status/user-available.png # <path to the touchpad icon on>
Icoff=/usr/share/icons/gnome/256x256/status/user-busy.png # <path to the touchpad icon off>
# because the value of "id" can change on xinput, the code does not rely on hardcoded id/master numbers
mainkey=`xinput list | grep "AlpsPS/2 ALPS DualPoint TouchPad"` # find your touchpad by using xinput
# above works if touchpad is enabled: "↳ AlpsPS/2 ALPS DualPoint TouchPad id=xx [slave pointer (y)]", or
# disabled: "∼ AlpsPS/2 ALPS DualPoint TouchPad id=xx [floating slave]"
idvar=`echo ${mainkey#*=}` # return "xx [slave pointer (y)]" or "xx [floating slave]" where xx=id number
idvar=`echo ${idvar%% *}` # return xx
#
touchvar=`echo ${mainkey#*[}` # return "slave pointer (y)]" or "floating slave]"
touchvar=`echo ${touchvar%% *}` # return "slave" or "floating"
if [ $touchvar = "floating" ] # touchpad currently disabled
then
mastkey=`xinput list | grep "Virtual core pointer"` # grab the master pointing string
# return "[ Virtual core pointer id=x [master pointer (y)]]"
mastkey=`echo ${mastkey#*"pointer ("}` # return "y)]"
mastkey=`echo ${mastkey%)*}` # return "y"
mastkey=$[$mastkey-1] # "y"-1 is the laptop touchpad master id
notify-send -i $Icon "Enabling touchpad..." \ "ON - Touchpad connected !"
echo "Enabling touchpad ..."
xinput reattach $idvar $mastkey
elif [ $touchvar = "slave" ] # touchpad currently enabled
then
notify-send -i $Icoff "Disabling Touchpad" \ "OFF - Touchpad disconnected"
echo "Disabling touchpad ..."
xinput float $idvar
fi