13

I would like to suspend my xubuntu (14.04) system from a keyboard shortcut without entering my superuser password (sudo). I'm looking a command line which I can convert to a shortcut.

So far, I tried two solutions:

Xfce command:

xfce4-session-logout --suspend

Problem: The system doesn't lock the session. I don't need to enter my password for the wake-up and I want to do it.

Dbus:

dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend

Problem: After wake-up, the Internet connection is down and I have to reboot the system to get it back.

Is there a third solution which 1. ask the password during the wake-up process, and 2. doesn't mess up with Internet connection?

In fact, the graphical default shortcut (from the menu) works fine. I just don't know which command line is called.

ppr
  • 1,887
  • 7
  • 23
  • 40

5 Answers5

9

I wrote a script. It seems to do what you ask for:

#!/usr/bin/env zsh
# Custom suspend
#
# (That 'zsh' up there can be switched to 'bash', or 
# pretty much any shell - this doesn't do anything too fancy.)
#
# Dependencies are mostly xfce stuff:
#
#   xbacklight
#   xflock4
#   xfce4-session-logout

# Set how dim we want the screen to go (percentage, out of 100)
dim=5

# Pack up your toys
previous_dimness=$(xbacklight -get)

# Turn down the lights
xbacklight -set $dim

# Lock the door (this requires a password to get back in)
xflock4

# And go to sleep
xfce4-session-logout --suspend

# When we wake up, turn the lights back on
xbacklight -set $previous_dimness
Jon Carter
  • 238
  • 2
  • 7
  • 1
    +1 for the wonderful comments. I think I will use this script when I install Ubuntu. – Wildcard Dec 12 '15 at 03:21
  • Im sorry but where should I place this script? how should I connect it with a keyboard shortcut (for example ctrl+alt+s)? I am using Lubuntu – hipoglucido Aug 12 '17 at 15:29
  • You can technically put the script anywhere. I have a bin/ directory under my home directory just for personal scripts like this that I want to use. In this case, the path to the script is: /home//bin/custom-suspend You'll want to make sure the script is executable. One way to do that is to run the following command: $ chmod +x /home//bin/custom-suspend To give it a shortcut under LXDE (which Lubuntu) uses, you should be able to search for something like 'keyboard' from the start menu, which should show you the keyboard config app. – Jon Carter Aug 14 '17 at 03:53
4

You can very simply send the command for it to lock screen first, and then have it suspend:

xscreensaver-command -lock ; xfce4-session-logout --suspend

For usage of xscreensaver-command, run xscreensaver-command --help

Wilf
  • 2,337
  • 2
  • 22
  • 39
  • That works from command line (although the lock screen is unnecessary since that's automatic with suspend), but not as a keyboard application shortcut (at least with Ubuntu 12.04). By the way, the Xfce app for locking the screen is xflock4 (no args), which by default is bound to control-alt-delete. – BobDoolittle Oct 22 '15 at 18:21
  • `xscreensaver-command` seems to be gone in 15.10. – Jesse Glick Jan 14 '16 at 23:54
  • @JesseGlick - just install the [`xscreensaver`](http://packages.ubuntu.com/wily/xscreensaver) package – Wilf Jan 15 '16 at 17:28
2

Oddly enough xfce4-session-logout --suspend works just fine, and my system is xubuntu 14.04. It also does lock the session, although I have switched on the option "lock screen before sleep", go to Settings->Session and Startup-> Advanced, and check if it switched on there.

Ufos
  • 192
  • 10
  • That works from command line (although the lock screen is unnecessary since that's automatic with suspend), but not as a keyboard application shortcut (at least with Ubuntu 12.04). – BobDoolittle Oct 22 '15 at 18:21
  • well, it is supposed to work in **x**ubuntu, not ubuntu. I am not sure why do you even have the `xfce4-session-logout` command. – Ufos Oct 23 '15 at 14:41
  • We are talking Xfce, which can be added to any ubuntu distribution. Xubuntu is simply a convenience distro that happens to have added Xfce packages and configured them as a desktop. You can start with ubuntu and add/configure it yourself. The xubuntu/ubuntu distinction is a red herring here. – BobDoolittle Oct 23 '15 at 18:21
  • Working fine for me, with screen lock, in Xubuntu 15.10. – Jesse Glick Jan 15 '16 at 00:25
0

This command works for me: I just make a launcher for desktop and set the Shutdown Icon for that. put this command in command filed:

dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend

fist time ask me to make Executable and after that working very well.

I'm using wicd for Internet connection and It's working well too after waking up!

Vahid
  • 101
  • 1
  • Xubuntu 15.10: `Error org.freedesktop.DBus.Error.UnknownMethod: Method "Suspend" with signature "" on interface "org.freedesktop.UPower" doesn't exist` – Jesse Glick Jan 14 '16 at 23:53
0

If you're on a laptop and just want a key to press. You can use the power button. The behavior can be set from the Power settings:

  1. Open Settings Manager (or by command : xfce4-settings-manager )
  2. Open Power Manager settings
  3. In General : set When power button is pressed to Ask
  4. Close Power Manager settings

If you have ACPI scripts installed, deactivate or update the power-button script from

/etc/acpi/events/, and change the action field to /bin/true:
# EXAMPLE
event=button/power.*
#action=/usr/lib/acpid/power_button
action=/bin/true

Ref: https://wiki.xfce.org/tips#solution_2

Mads Hansen
  • 111
  • 3