I want to have my touchpad disabled automatically when an external mouse is connected and enabled when there is none. I have tried using touchpad-indicator
but that fails in cases when the computer has been put to sleep with a mouse connected and awoken with the mouse disconnected.
I have tried to make the following script into a daemon to solve this issue but I can't get it to work:
#!/bin/bash
declare -i TID
declare -i MID
TID=`xinput list | grep -Eo 'Touchpad\s*id\=[0-9]{1,2}' | grep -Eo '[0-9]{1,2}'`
MID=`xinput list | grep -Eo 'Mouse\s*id\=[0-9]{1,2}' | grep -Eo '[0-9]{1,2}'`
if [ $MID -gt 0 ]
then
xinput disable $TID
else
xinput enable $TID
fi
I tried start-stop-daemon -S -x ./myscript.sh -b
and setsid ./myscript.sh >/dev/null 2>&1 < /dev/null &
and nohup ./myscript 0<&- &>/dev/null &
and even ./myscript.sh &
All of these return some 4-digit number, which, I guess, should be PID of the started process but when I launch lxtask there are no processes with this PID, even if I tick "view all processes". And, of course, it doesn't work!
xinput
needs a running X server, and most methods of running stuff as daemons have no knowledge of or ability to connect to X. Third, and the main reason why you should always explain what you are trying to do is that very often the solution that someone is attempting to apply is not actually the way to get it done and you end up asking the wrong question, commonly known as the XY problem.