dbus-send --session --dest=org.freedesktop.ScreenSaver --type=method_call \
--print-reply /ScreenSaver org.freedesktop.ScreenSaver.Lock
This will work with KDE4 and should as well work with newer Gnome versions. Tested with KDE 4.1 beta1. It needs the display variable to be set and be run as the appropriate user.
e.g. su $user -c "DISPLAY=:0 dbus-send... "
In Ubuntu 8.04 you can change your /etc/acpi/resume.d/90-xscreensaver.sh to lock the screen on resume like this:
#!/bin/sh
# now, we should poke xscreensaver so you get a dialog
#if pidof xscreensaver > /dev/null; then
for x in /tmp/.X11-unix/*; do
displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
getXuser;
if [ x"$XAUTHORITY" != x"" ]; then
export DISPLAY=":$displaynum"
su $user -c "(xscreensaver-command -deactivate)"
su $user -c "dbus-send --session --dest=org.freedesktop.ScreenSaver \
--type=method_call --print-reply /ScreenSaver \
org.freedesktop.ScreenSaver.Lock"
fi
done
#fi
I needed this. Thanks a lot! :)
ReplyDeleteI'm glad it helped. Often takes some time to figure it out, always nice to help others save time.
ReplyDeleteunder kde 3.5, it was
ReplyDelete$ dcop kdesktop KScreensaverIface lock
How I can unlock the screen via dbus from screensaver without entering password? I try to setup BlueProximity working with KDE4 screensaver.
ReplyDeleteI can lock via command:
$ qdbus org.kde.krunner /ScreenSaver Lock
but don't know how to unlock...
Hmmm... may I ask why you would want to circumvent entering the password?
ReplyDeleteI want to lock computer when my mobile phone with bluetooth go away, and unlock when I with my phone goes back to computer.
ReplyDeleteProgram BlueProximity do this, but work only with gnome screensaver:
Lock:
gnome-screensaver-command -l
Unlock without password:
gnome-screensaver-command -d
And I want to do this function in KDE.
Ah... ok. Well in my experience it usually works quite well to simply killall (screensaver) (kscreenlock...).
ReplyDeleteJust look at the processes active when it's locked. Good luck! And maybe you want to post the script. It would be a nice feature to include this automatically. :)
I have no script, I using the program BlueProximity with thouse settings:
ReplyDeleteLock:
qdbus org.kde.krunner /ScreenSaver Lock
Unlock without password:
qdbus org.kde.krunner /ScreenSaver SetActive false
second string I get from kbluetooth 0.4 sources.
I have found a working variant!
ReplyDeleteqdbus didn't send the values, dbus-send do this.
Working commands:
Lock:
dbus-send --type=method_call --dest=org.freedesktop.ScreenSaver /ScreenSaver org.freedesktop.ScreenSaver.Lock
Unlock without password:
dbus-send --type=method_call --dest=org.freedesktop.ScreenSaver /ScreenSaver org.freedesktop.ScreenSaver.SetActive boolean:false
Here is what i am doing :)
ReplyDelete#!/bin/sh
for x in /tmp/.X11-unix/*; do display=`echo $x | sed s#/tmp/.X11-unix/X##`; done
for x in /tmp/kde-*; do user=`echo $x | sed s#/tmp/kde-##`; done
export DISPLAY=":$display"
su $user -c "qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock"