How to create keyboard shortcut which initiates suspend

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
Asked By: user364819

||

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.

Answered By: Jacob Vlijm

You can just add this

gksudo pm-suspend

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

Answered By: peeyush113

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 😉

Answered By: A.B.

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.

Answered By: practicalli-john

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.

Answered By: heikrana

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'
Answered By: panticz