Saturday 22 March 2014

Script for toggling mouse in Linux




My one year old nephew cannot hold without touching my laptop mouse with glowing lights in it. He likes playing, pressing and even eating it! You cannot plug your mouse out as the light goes off and he gets angry. So, here is a small recipe I wrote to make my valuable work safe from his turbulent hands:

Make a file in your home directory: .mouse. It looks like this:

 #!/bin/bash
a=`xinput --list |grep "Logitech USB Optical" |cut -f2|cut -d'=' -f2`
b=`xinput --list-props $a |head -2|tail -1|cut -f3`
echo "Mouse currently in $b state. (Enabled-> 1, Disabled-> 0)"

if [ $b -eq 1 ]

then
echo "Disabling Mouse"
xinput set-prop $a "Device Enabled" 0
else
echo "Enabling Mouse";
xinput set-prop $a "Device Enabled" 1
fi

unset a; unset b;

And once done with that, all you need to do is to have a hot key assigned to it. Ctrl-M seems good to me. And you just need this screenshot to set that up.




Save, and you are all set!