Is there a way to toggle touchpad on/off with a command/keyboard shortcut?

Is there a way to toggle touchpad on/off with a command/keyboard shortcut? I tried using this:

if $(gsettings get org.gnome.settings-daemon.peripherals.touchpad touchpad-enabled); then gsettings set org.gnome.settings-daemon.peripherals.touchpad touchpad-enabled false; else gsettings set org.gnome.settings-daemon.peripherals.touchpad touchpad-enabled true; fi

But it didn't work at all.


Work Around:

with the help of this post https://askubuntu.com/a/1140700/739431

install the xdotool package if not yet installed, sudo apt install xdotool

  1. run xmodmap -pke | grep TouchpadToggle

example

pratap@i7:~$ xmodmap -pke | grep TouchpadToggle
keycode  71 = XF86TouchpadToggle NoSymbol XF86TouchpadToggle NoSymbol NoSymbol NoSymbol NoSymbol NoSymbol NoSymbol NoSymbol XF86TouchpadToggle
keycode 199 = XF86TouchpadToggle NoSymbol XF86TouchpadToggle NoSymbol XF86TouchpadToggle
pratap@i7:~$ 
  1. run in terminal xdotool key XF86TouchpadToggle to check if the touchpad toggling is working?

enter image description here

  1. Create your own shortcut Shift+Ctrl+I with custom command xdotool sleep 1 key XF86TouchpadToggle sleep value 0.5 may also work.. try it with your comfort..

enter image description here