8

When I was running the Unity shell I was able to do Fn + F1 and get my machine to suspend, however now that I am running Gnome Shell, when I do this keyboard shortcut, absolutely nothing happens, so I was wondering if there was anyway to get it so that when doing that keyboard shortcut, my machine does actually suspend?

I have tried looking in my System Settings and found nothing obvious, I have also looked in Gnome Tweak Tool, but still nothing obvious. When I had Unity it was just the case though, and even when I had Windows 7 before that it was the case that that keyboard combination did that, I have never needed to configure anything specially, nor have I to get this working.


OS Information:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 15.04
Release:    15.04
Codename:   vivid

6 Answers6

17

I tested the command mentioned here on Gnome 15.04, and it did the job well. The next thing to do is then to make it available under a shortcut key.

The easiest way would be to create a small script of it:

#!/bin/bash

dbus-send --system --print-reply \
  --dest="org.freedesktop.login1" \
  /org/freedesktop/login1 \
  org.freedesktop.login1.Manager.Suspend boolean:true

save it as initiate_suspend.sh, and make it available under a shortcut key. To do that works the same in Gnome as it works in Unity: choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:

/bin/bash /path/to/initiate_suspend.sh

to a shortcut key combination of your choice.

Jacob Vlijm
  • 82,471
  • 12
  • 195
  • 299
  • Comments are not for extended discussion; this conversation has been [moved to chat](http://chat.stackexchange.com/rooms/26269/discussion-on-answer-by-jacob-vlijm-how-to-create-keyboard-shortcut-which-initia). – Mitch Jul 26 '15 at 18:34
  • @Mitch sorry (again) I'll remember for next time. – Jacob Vlijm Jul 26 '15 at 18:36
  • No worries.. -:) – Mitch Jul 26 '15 at 18:37
  • Seems to work in Xfce, too, though it does not lock desktop. (Xfce has a specific command `xfce4-session-logout --suspend` which does, if set) – jarno Apr 08 '21 at 00:59
4

To suspend Ubuntu 18.10 I use the Super key to launch a command and type sus to highlight the Suspend command, then hit Return.

screenshot

Not quick as elegant as Super+l to lock screen, but it works without adding any configuration and no need for a mouse.

Pablo Bianchi
  • 14,308
  • 4
  • 74
  • 117
practicalli-john
  • 3,171
  • 1
  • 20
  • 15
4

I know this post is old. But in new Gnome versions, it's very easy.

Simply go to settings > keyboard > keyboard shortcuts and add a custom shortcut with this command systemctl suspend.

heikrana
  • 361
  • 3
  • 9
0

Here a exaple how to create keyboard shortcut to suspend the system by pressing <Super> + s keys:

gsettings set org.gnome.settings-daemon.plugins.media-keys suspend "['<Super>s']"

or create a custom keybinding:

gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybindings "['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/']"
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ name 'suspend'
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ command 'systemctl suspend'
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ binding '<Super>p'
panticz
  • 1,588
  • 13
  • 14
0

You can just add this

gksudo pm-suspend

in Settings>>Keyboard>>Shortcut and map it to any key combination you want.

A.B.
  • 89,123
  • 21
  • 245
  • 323
peeyush113
  • 11
  • 2
0

Using pm-utils with PolicyKit

With this way, you have to enter a password before suspend.

  1. First install pm-utils, we need pm-suspend

    sudo apt-get install pm-utils
    
  2. After that, create a new script file and add the code below

    #!/bin/sh
    pkexec "pm-suspend" "$@"
    
  3. Open Keyboard via Activities menu and navigate to Custom Shortcuts and add a new shortcut.

    screenshot

    screenshot

  4. Now add a new file in /usr/share/polkit-1/actions/

     sudo nano cat /usr/share/polkit-1/actions/pm-suspend.policy
    

    And add the lines below

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE policyconfig PUBLIC
     "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
     "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
    
    <policyconfig>
    
      <action id="org.freedesktop.policykit.pkexec.run-pm-suspend">
        <description>Run FlashTool</description>
        <message>Authentication is required to run pm-suspend</message>
        <defaults>
          <allow_any>no</allow_any>
          <allow_inactive>no</allow_inactive>
          <allow_active>auth_admin_keep</allow_active>
        </defaults>
        <annotate key="org.freedesktop.policykit.exec.path">/usr/sbin/pm-suspend</annotate>
        <annotate key="org.freedesktop.policykit.exec.allow_gui">TRUE</annotate>
      </action>
    
    </policyconfig>
    

That's all ;)

Pablo Bianchi
  • 14,308
  • 4
  • 74
  • 117
A.B.
  • 89,123
  • 21
  • 245
  • 323