Re: Checking whether Gnome screensaver currently active

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Monday, January 17, 2011 10:57:00 pm Robert Nichols wrote:
> On 01/17/2011 09:57 PM, Rick Sewill wrote:
> > Question please:
> > 
> > Can you use
> > gnome-screensaver-command -q
> > 
> > man gnome-screensaver-command
> > 
> > I'm currently trying out KDE so I don't know
> > what is returned by the above command for the
> > various gnome-screensaver states.
> 
> As I said in my original message, when run from a cron job that fails:
> 
>       ** Message: Failed to connect to the D-BUS daemon: /bin/dbus-launch
>       terminated abnormally with the following error: Autolaunch error:
>       X11 initialization failed.
> 
> And yes, I did try it with "DISPLAY=:0.0" in the environment.

You have a good puzzle!

I read all the responses for the problem,
http://www.mail-archive.com/debian-kde@xxxxxxxxxxxxxxxx/msg30421.html

I tried to condense their answer to the following...please give it a try:

I created a file, ${HOME}/bin/testscreensaver
===== Please begin contents of file testscreensaver with following line
#!/bin/bash

# We must set the DISPLAY variable so dbus is happy.

export DISPLAY=:0.0

# We must find the DBUS_SESSION_BUS_ADDRESS so dbus is happy.

for pid in $(pgrep -u $USER) 
do 
    declare DBUS_SESSION_BUS_ADDRESS=$(cat /proc/${pid}/environ | \
            tr '\0' '\n' | grep "DBUS_SESSION_BUS_ADDRESS=")

# I looked for the first DBUS_SESSION_BUS_ADDRESS found.
    [ -z "${DBUS_SESSION_BUS_ADDRESS}" ] || break
done


# Strip off the DBUS_SESSION_BUS_ADDRESS= string at the beginning.
DBUS_SESSION_BUS_ADDRESS="${DBUS_SESSION_BUS_ADDRESS:25}"

# I echo it for debugging purposes...you probably don't want to echo it.
echo "Set bus address to <${DBUS_SESSION_BUS_ADDRESS}>"

# If I have a string, I call the gnome-screensaver-command
[ -z "${DBUS_SESSION_BUS_ADDRESS}" ] || gnome-screensaver-command -q

===== Please end file testscreensaver with previous line

Also, I should note, in my crontab, I do the following,
I don't know if this matters and would try the above without the following:
SHELL=/bin/bash
BASH_ENV=/home/rsewill/.bash_profile

With this, I can schedule the ~/bin/testscreensaver to run, as a cron job,
and it produces output, like the following:

=====When I don't have gnome-screensaver running, I get an email:
<I am ignoring extraneous cron job information in the email from cron>
...
Set bus address to <unix:abstract=/tmp/dbus-
YgC81q8iml,guid=79ff8927f8fb4aee96ab1501000110f0>
** Message: Screensaver is not running!

=====When I have gnome-screensaver running, but not active, I get:
<I am ignoring extraneous cron job information in the email from cron>
...
Set bus address to <unix:abstract=/tmp/dbus-
YgC81q8iml,guid=79ff8927f8fb4aee96ab1501000110f0>
The screensaver is inactive
The screensaver is not inhibited

Your mileage may vary...this feels like a "kludge" which may break
when dbus or other things get updated/changed.

Attachment: signature.asc
Description: This is a digitally signed message part.

-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines

[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux