A new need has come for me. I want to activate or deactivate the touchpad from the shell.
In this post, I will concentrate on how to trigger on/off the touchpad from the shell.
Pre-requisites
The package xinput. It should already be installed.
Just in case:
sudo aptitude install xinput
Manual
Here is the script to manually toggle it on/off.
Actions:
- It first retrieves the status the script is given.
- If empty, it does set the 1 which means, activate it.
- Then retrieve the id of the touchpad.
- At last, trigger the on/off status depending on the status.
code
#!/usr/bin/env bash # Use: $0 <STATUS> # By default the touchpad is activated! # $0 1: To activate the touchpad with id <ID> # $0 0: To deactivate the touchpad with id <ID> TOUCHPAD_STATUS=${1-:"1"} TOUCHPAD_ID=$(xinput list\ | grep -i touchpad \ | grep -o "id=[0-9]*" \ | cut -f 2 -d'=') # activate or deactivate? [ $TOUCHPAD_STATUS = "1" ] && ACTION="--enable" || ACTION="--disable" # commit the actions xinput $ACTION $TOUCHPAD_ID
use
Activate the touchpad
toggle-touchpad-manual.sh 1
Deactivate the touchpad
toggle-touchpad-manual.sh 0
Auto
Toggle automatically on/off the touchpad.
code
It's almost the same script as before. But this one does request the current status of the touchpad and then inverse the status. For doing so, it calls the previous script one with the new status as parameter.
#!/usr/bin/env bash # Use: $0 # Toggle automatically on/off the touchpad depending its state WDIR=$(readlink -f $(dirname $0)) # Find the identifier of the touchpad TOUCHPAD_ID=$(xinput list \ | grep -i touchpad \ | grep -o "id=[0-9]*" \ | cut -f 2 -d'=') TOUCHPAD_STATUS=$(xinput --list-props $TOUCHPAD_ID \ | grep "Device Enabled " \ | cut -d':' -f 2) [ $TOUCHPAD_STATUS = "0" ] && NEW_STATUS="1" || NEW_STATUS="0" $WDIR/toggle-touchpad-manual.sh $NEW_STATUS
src: toggle-touchpad.sh
use
~/bin/stumpwm/toggle-touchpad.sh
If enabled, the touchpad will be disabled, else it will be enabled.
Example
This works on my:
- personal asus zenbook - ubuntu 12.10
- pro hp elitebook - ubuntu 12.10
Conclusion
In this post, I presented how to activate/deactivate the touchpad from the shell.
In another post, I'll present a possible orchestration using those scripts as a basic brick.