------
/etc/udev/rules.d/10-local.rules
------
ACTION=="add", SUBSYSTEM=="input", KERNEL=="mouse[0-9]", ENV{DISPLAY}=":0",ENV{XAUTHORITY}="/home/user/.Xauthority", ENV{ID_CLASS}="mouse", RUN+="/bin/touchpad_switcher.sh false"
ACTION=="remove", SUBSYSTEM=="input", KERNEL=="mouse[0-9]", ENV{DISPLAY}=":0",ENV{XAUTHORITY}="/home/user/.Xauthority", ENV{ID_CLASS}="mouse", RUN+="/bin/touchpad_switcher.sh true"
------
/bin/touchpad_switcher.sh
------
#!/bin/sh
enabled=$1
touchpad_id=$(xinput | grep -i "touchpad" | cut -f2 | cut -d '=' -f2);
if $enabled
then
xinput set-prop $touchpad_id "Device Enabled" 1 | notify-send "The touchpad is now enabled." ""
else
xinput set-prop $touchpad_id "Device Enabled" 0 | notify-send "Disabling the touchpad..." ""
fi