Friday, May 3, 2024
 Popular · Latest · Hot · Upcoming
10
rated 0 times [  10] [ 0]  / answers: 1 / hits: 6915  / 2 Years ago, tue, february 1, 2022, 10:55:49

I'm using Xubuntu 12.04. In the Power Manager, I have checked Extended -> Lock screen when going for suspend/hibernate. If I choose to suspend from the main menu / Panel 1, the screen is locked. However, if I use dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend (see How can I suspend/hibernate from command line?; I use this command via a keyboard shortcut), the screen is not locked. How can I (1) suspend the system (2) have the screen locked at the same time (3) do not require root rights to do so [since I would like the command to be assigned to a keyboard shortcut].


More From » 12.04

 Answers
6

You can do that by using the following:



gnome-screensaver-command --lock && dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend


In a keyboard shortcut you need to put sh -c "<command>" replacing <command> with the command above, like:





sh -c "gnome-screensaver-command --lock && dbus-send --system --print-reply --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend"


If the above command does not work, you can also try using a shell script file (for example suspend_lockscreen.sh). First create the file call the following commands in a console:



cd ~
echo "gnome-screensaver-command --lock" >> suspend_lockscreen.sh
echo "dbus-send --system --print-reply --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend" >> suspend_lockscreen.sh
chmod +x suspend_lockscreen.sh


That will create a file named suspend_lockscreen.sh in the user home folder. Then, in the shortcut just call: ./suspend_lockscreen.sh.



Note: gnome-screensaver-command can be replaced by xscreensaver-command, as pointed out in one comment.


[#38323] Thursday, February 3, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sertold

Total Points: 445
Total Questions: 123
Total Answers: 113

Location: Burundi
Member since Wed, Sep 28, 2022
2 Years ago
;