I want to check, inside a bash script, how long the user of a X session has been idle.
The user himself does not have to be using bash, but just X. If the user just moved the mouse, for example, a good answer would be "idle for 0 seconds". If he has not touched the computer in 5 minutes, a good answer would be "idle for 300 seconds"
The reason to not use xautolock straight away is to be able to implement some complex behavior. For example, if the user is idle for 10 minutes, try to suspend, if he is idle for more 5 minutes, shutoff (I know it sounds odd, but suspend does not always work here ...)
timeout
command which can be quite handy in the toolkit. I've been usingxprintidle
for years though and will continue to keep it in the toolkit. – WinEunuuchs2Unix Jan 05 '21 at 18:32stat
%s
format sequence checks the size of the file, and the file can be different without the size changing. – Ian D. Allen Apr 04 '22 at 02:44stat
and spawning two subshells to compare the files, it's easier to usecmp
. Theif
statement would change toif cmp --silent /tmp/.{,last_}input; then
.cmp
compares the files byte by byte and stops as soon as it finds a difference. Also, if you're using wayland,xprintidle
andxinput
probably won't work. So, check this answer for an alternative: https://unix.stackexchange.com/a/492328/232740 – Felipe Apr 28 '22 at 17:39