Source: https://www.commandlinefu.com/commands/view/19659/toggle-the-touchpad-on-or-off
Put the command in a script:
#!/bin/bash
tp=$(synclient -l | grep TouchpadOff | awk '{ print $3 }') && tp=$((tp==0)) && synclient TouchpadOff=$tp
Another command that can be used is
synclient TouchpadOff=$(synclient -l | grep -q 'TouchpadOff.*1'; echo $?)
Make that script executable. Create a shortcut to run the script.
UPDATE: As the synclient
method may not work on newer systems:
#!/bin/sh
# This shell script is PUBLIC DOMAIN. You may do whatever you want with it.
TOGGLE=$HOME/.toggle_touchpad
if [ ! -e $TOGGLE ]; then
touch $TOGGLE
xinput disable 14
notify-send -u low -i mouse --icon=/usr/share/icons/HighContrast/256x256/status/touchpad-disabled.png "Trackpad disabled"
else
rm $TOGGLE
xinput enable 14
notify-send -u low -i mouse --icon=/usr/share/icons/HighContrast/256x256/devices/input-touchpad.png "Trackpad enabled"
fi
In the above commands 14
is a variable to be identified with xinput list
~$ xinput list
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ Sony Vaio Jogdial id=8 [slave pointer (2)]
⎜ ↳ BM30X mouse id=12 [slave pointer (2)]
⎜ ↳ AlpsPS/2 ALPS GlidePoint id=14 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ Video Bus id=6 [slave keyboard (3)]
↳ Sony Vaio Keys id=7 [slave keyboard (3)]
↳ Video Bus id=9 [slave keyboard (3)]
↳ Power Button id=10 [slave keyboard (3)]
↳ USB 2.0 Camera: USB Camera id=11 [slave keyboard (3)]
↳ AT Translated Set 2 keyboard id=13 [slave keyboard (3)]
To identify the name of the device in that list look in the Mouse & Touchpad settings

This script also shows a notification with icon, as well as message.
Sources here, here, also here.