Checking whether Gnome screensaver currently active

Robert Nichols rnicholsNOSPAM at comcast.net
Tue Jan 18 03:01:46 UTC 2011


On 01/17/2011 04:25 PM, JB wrote:
> JB<jb.1234abcd<at>  gmail.com>  writes:
>
>> ...
> Google search: linux keyboard mouse activity
>
> Example:
> http://stackoverflow.com/questions/222606/detecting-keyboard-mouse-activity-in-linux

Thanks.  That little C program will (with a suitable value for the DISPLAY
environment variable) report the idle time when run from a cron job, but
what I really need is whether the screensaver is running (screen locked)
rather than how recently the cat might have stepped on my keyboard or
moved the mouse.  Sorry that I wasn't very clear about that before.

Right now, checking on the number of child processes of gnome-screensaver
still looks like my best bet:

     ssID=$(pgrep -n gnome-screensav)
     if [ "$ssID" ] && [ $(ps -g $ssID -o pid= | wc -l) -lt 2 ]; then
         # Screen saver enabled but not active
         ...
     fi

-- 
Bob Nichols     "NOSPAM" is really part of my email address.
                 Do NOT delete it.



More information about the users mailing list