On Fri, May 04, 2007 at 01:32:02AM +0200, Marcus Libäck wrote: > Hello, > > I'm trying to activate gnome-screensaver from /etc/acpi/sleepbtn.sh so > that the screen is locked when I resume the laptop. With xscreensaver it just > seems to be a matter of running something like: > # su $user -c "xscreensaver-command -lock" > > But with the gnome-screensaver equivalence I get the following error: > > # su $user -c "gnome-screensaver-command --lock" > gnome-screensaver-Message: Failed to connect to the D-BUS daemon: Failed > to execute dbus-launch to autolaunch D-Bus session > > It also fails if I try to send a DBus message: > # su $user -c "dbus-send --session \ > --dest=org.gnome.ScreenSaver \ > --type=method_call \ > --print-reply \ > --reply-timeout=20000 \ > /org/gnome/ScreenSaver \ > org.gnome.ScreenSaver.Lock" > Failed to open connection to session message bus: Failed to execute > dbus-launch to autolaunch D-Bus session > > Am I missing something here? Shouldn't it be possible to activate the > screensaver from outside of the user's X session?
it is possible... I just did it!! I wanted to see if I could figure this out as a way to help learn about environments. The key here is that you've got no DBUS_SESSION_BUS_ADDRESS defined. And you've got to get the right one. Here's how I hacked it. from my X session, in a terminal, run set | grep DBUS > tempenv then from a vt as root I ran source tempenv which gets that environment variable set in the current login session. then you have to export that variable before you can access the dbus session. export DBUS_SESSION_BUS_ADDRESS; su $user -c \ "gnome-screensaver-command --lock" and lo and behold it works. It does spit out an error, but its the same error that is spit out if you run the command within the x session and it doesn't prevent it from locking. So you have to somehow get that variable out of your X session, maybe by putting that set | grep command at the end of your .xinitrc or whatever you use to launch X. and then you've got to somehow export that variable so that the gnome-screensaver-command can access it. hth. A
signature.asc
Description: Digital signature