Foi assim que funcionou para mim no Ubuntu 16.04.
Primeiro, crie o script para ativar e desativar o touchpad. Saiba como o touchpad é chamado:
xinput list
Emseguida,crieoarquivoNAMEOFSCRIPT.sh
#!/bin/sh
#
# Enables the touchpad if and only if there aren't any external mice connected.
#
# Originally from:
# https://wiki.archlinux.org/index.php/Touchpad_Synaptics#System_with_multiple_X_sessions
#Here puts how is named
TOUCHPAD="PS/2 Synaptics TouchPad"
FOUND=0
for MOUSE in 'find /sys/class/input -name mouse\*'
do
if [ "'cat $MOUSE/device/name'" != "$TOUCHPAD" ]
then
FOUND=1
#Find a Mouse device other than the TouchPad and record the variable.
break
fi
done
DISPLAY=:0
export DISPLAY
for USER in 'w -h | cut -d\ -f1 | sort | uniq'
do
XAUTHORITY='sudo -Hiu $USER env | grep ^HOME= | cut -d= -f2'/.Xauthority
export XAUTHORITY
TOUCHPADDEVICE=$(($(xinput list | grep -i touchpad | cut -d= -f2 | cut -d[ -f1)+0))
#Find the Touchpad Id
if [ $FOUND -eq 1 ]; then
#If another device is founded, disable touchpad
xinput disable $TOUCHPADDEVICE
else
#else enable touchpad
xinput enable $TOUCHPADDEVICE
fi
done
Não se esqueça de torná-lo executável!
chmod +x NAMEOFSCRIPT.sh
Em seguida, crie a regra (requer raiz)
gksudo gedit /etc/udev/rules.d/01-touchpad_toggle.rules
(Pode ser qualquer nome, de preferência atribuir 01
ao início)
SUBSYSTEM=="input", KERNEL=="mouse[0-9]*", ACTION=="add", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/**$USERNAME**/.Xauthority", RUN+="**PATH TO NAMEOFSCRIPT.SH**"
SUBSYSTEM=="input", KERNEL=="mouse[0-9]*", ACTION=="remove", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/**$USERNAME**/.Xauthority", RUN+="**PATH TO NAMEOFSCRIPT.SH**"
Se tudo correr bem, quando eu conectar o mouse USB, ele desativa o Touchpad e, quando desconectado, ativa-o.
Para aqueles que têm problemas para serem reconhecidos pelo mouse USB, execute lsusb
desconectado e, em seguida, lsusb
conectado.
Fontes: link