I would like to execute a command such as
if my Linux machine has been idle for 5 minutes.
By idle, I mean the same thing a screen saver that gets activated would use to define "idle".
I use a program called
It is a very simple application: it returns the amount of milliseconds since last X interaction:
(note: due to the underlying system, it will consistently give a value in ms slightly lower than the "actual" idle time).
You can use this to create a script that runs a certain sequence after five minutes of idle time via e.g.:
The 100 ms offset is because of the earlier noted quirk that
I have used a similar approach in a Perl script (an irssi plugin) for quite some time, but the above was just written and has not really been tested except for a few trial runs during writing.
Try it by running it in a terminal within X. I recommend setting the timeout to e.g. 5000 ms for testing, and adding
Here's a C application that I found which you can compile.
It needs a couple libraries to build. On my Fedora 19 system I needed the following libraries:
Once these were installed I compiled the above like so:
You can see that it's able to report the number of seconds that X is detecting as idle time by running it like so:
Using this executable you could put together a script that can do something like this, monitoring the idle time reported by
The above shows
NOTE: You could incorporate your
Then you can use the following shell script:
bsd ports (packages collection) has a program that can do this:
note that the -program needs to contain the full path to the binary, as it's passed to execv().
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?