Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Bash script/utility to wait for keyboard and mouse inactivity
Sometimes you may want to have some script periodically popping up some interface or something, but it may be somewhat abrupt, interrupt something you're doing with the mouse, or keyboard. So I came up with this tiny utility that will wait for the time given as a parameter, then exit.
I don't even understand how the detection of keyboard activity works, I got it from somewhere, and works in my hardware.
Usage example: "after-idle.sh && mypopsubroutine", if you have the script in your "path", or it converted in a sobroutine into the script itself.
Code:
#!/bin/bash a=0 time=$1 if [ -z $time ] ; then time="1.2s" ; fi while true ; do mouse1=$( xdotool getmouselocation --shell | head -n 1 | sed 's|X=||') kb1=$( grep i8042 /proc/interrupts | awk '{ print $2}' ) sleep $time mouse2=$( xdotool getmouselocation --shell | head -n 1 | sed 's|X=||') kb2=$( grep i8042 /proc/interrupts | awk '{ print $2}' ) if [ $mouse1 -eq $mouse2 ] && [ $kb1 -eq $kb2 ] ; then a=$((a+1)) echo ... if [ $a -gt 4 ] ; then # echo xscreensaver action exit 0 fi else a=0 echo user activity... fi done
Usage example: "after-idle.sh && mypopsubroutine", if you have the script in your "path", or it converted in a sobroutine into the script itself.
Total Comments 0