Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
47
rated 0 times [  47] [ 0]  / answers: 1 / hits: 24932  / 2 Years ago, thu, august 11, 2022, 3:30:45

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 ...)


More From » xorg

 Answers
7

Just found a simple way to do it.


There is a program called xprintidle that does the trick


getting the idle time (in milliseconds) is as simple as


xprintidle

and to install


apt-get install xprintidle



For sysadmins, it also works remotely


From an ssh session:


export DISPLAY=:0 && sudo -u john xprintidle

where john is the user logged into the X session on the remote machine.




Note that some programs such as MPlayer seem to reset the counter.


That might be desirable or not depending on your application. For me I meant to use it to suspend the computer and the MPlayer exception is helpful.


There is another answer (https://askubuntu.com/a/1303464/56440) for those who want no resetting, but I haven't personally tested it


[#34918] Thursday, August 11, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
egantfis

Total Points: 406
Total Questions: 108
Total Answers: 108

Location: Austria
Member since Thu, Jan 7, 2021
3 Years ago
egantfis questions
Mon, Nov 1, 21, 03:37, 3 Years ago
Fri, Mar 18, 22, 23:26, 2 Years ago
Mon, Mar 6, 23, 05:03, 1 Year ago
Sun, Oct 3, 21, 23:30, 3 Years ago
Thu, Mar 10, 22, 12:28, 2 Years ago
;