Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How can I suspend my computer from the command line and, once it wakes up, display Unity's lock screen? I want to replicate exactly what happens when I click on the system cog icon at the top right of the Unity panel and go to Suspend in Ubuntu 14.04 (not an earlier version!).

I've found many answers that do not work, such as those found here and here. All of them are for older versions of Ubuntu or invoke either gnome-screensaver or xscreensaver's lock screen.

This command, for instance, suspends the computer, but does not lock the screen: dbus-send --system --print-reply --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend, despite Require my password when waking from suspend being checked in the Brightness & Lock system settings.

Actually, I don't even know how to invoke Unity's lock screen at all in 14.04: the closest I can come to is dm-tools lock, but this is not quite the same, as it allows you to sign in as a different user and shows more indicators.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Since I figured out how to get the 14.04 lock screen, I just chained the dbus lock command with the suspend one:

sh -c "dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock && dbus-send --system --print-reply --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.