So I recently wrote a script that toggles my laptop's touchpad on or off using xinput, and it works beautifully when run from terminal. I was attempting to set this script to auto-run whenever my mouse is plugged in, but it seems to be running the script (echo statements I put in the script for debugging are working) without actually disabling the touchpad. I am using halevt to detect the device and launch the command, so I assume I am doing something wrong with halevt and permissions. Any ideas?
The Script:
Code:
# toggleTouchpad by Brendon Dugan
# Toggles a touchpad on or off depending on it's current state or CLI argument
#
# To configure, run the command 'xinput list' in terminal and identify your touch pad.
# Using the output of the above command, change the touchpadString variable to a substring
# of your touchpad's description that is unique to that device.
#
# To run, simply type 'toggleTouchpad' to toggle your touchpad on or off, or
# 'toggleTouchpad on' to explicitly turn your touchpad on, or
# 'toggleTouchpad off' to explicitly turn it off.
#
# Enjoy!
touchpadString="TouchPad"
touchpadID=$(xinput list | grep $touchpadString | awk -F " " '{print $6}' | awk -F "=" '{print $2}')
touchpadEnabled=$(xinput list-props $touchpadID | grep "Device Enabled" | awk -F ":" '{print $2}')
# Check for arguments on the command line
if test $# -eq 1
then
# Change the argument to lowercase
arg1=$(echo $1 | tr [:upper:] [:lower:])
cliArg=1
else
# There is no argument.
cliArg=0
fi
if [ $cliArg -eq 1 ]
then
# If there's an argument, check to see whether it is on, off, or junk
if [ $arg1 = 'on' ]
then
# The argument was 'on', so turn the touchpad on
xinput --set-prop $touchpadID "Device Enabled" 1
echo "ON"
elif [ $arg1 = 'off' ]
then
# The argument was 'off', so turn the touchpad off
xinput --set-prop $touchpadID "Device Enabled" 0
echo "OFF"
else
# The argument was junk, so do nothing
sleep 1
fi
else
# There was no argument, so just toggle the touchpad to the opposite
# of the state it has now.
if [ $touchpadEnabled -eq 1 ]
then
xinput --set-prop $touchpadID "Device Enabled" 0
else
xinput --set-prop $touchpadID "Device Enabled" 1
fi
fi
The command to launch halevt:
Code:
sudo halevt -u brendon -g brendon -c /home/brendon/.halevt.xml
The halevt config file:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<halevt:Configuration version="0.1" xmlns:halevt="http://www.environnement.ens.fr/perso/dumas/halevt.html">
<halevt:Device match="hal.info.udi = /org/freedesktop/Hal/devices/usb_device_46d_c70e_00076142E023">
<halevt:Insertion exec="/home/brendon/bin/toggleTouchpad off"/>
<halevt:Removal exec="/home/brendon/bin/toggleTouchpad on"/>
</halevt:Device>
</halevt:Configuration>
Bookmarks