Ubuntu – How to toggle xinput device prop

bashtouchpad

I can disable a device like this:

xinput set-prop 13 "Device Enabled" 0

But I want to actually set a custom shortcut that toggles this between 0\1. My bash skills are kinda rusty, so how can I do this? There's no get-prop command, I got this far:

xinput list-props 13 | grep "Device Enabled"

Which correctly prints out

Device Enabled (135):   1

But I don't know what to do next. Help?

Best Answer

Toggle xinput device on or off with following bash script.

#!/bin/bash

device=13
state=$(xinput list-props "$device" | grep "Device Enabled" | grep -o "[01]$")

if [ $state == '1' ];then
  xinput --disable "$device"
else
  xinput --enable "$device"
fi
Related Question