105

When I press the power button a dialog opens, but I want to shutdown the system without receiving "Do you really really want to shutdown?". How can I choose a direct shutdown action on a pressed power button?

I had the same problem with the 11.04 version, but I don't remember the solution and yesterday I upgraded to Ubuntu 11.10.

Alvar
  • 17,038
NaN
  • 1,435

9 Answers9

94

Lid Close Action

To set up the Laptop Lid Close Action you have to install Advanced Setting (or the Gnome Tweak Tool). It is in the USC (Ubuntu Software Center) under either tweak or Advanced Settings. If installed press the super button and type in tweak or advanced and choose the Advanced Settings. When it opens choose the shell tab;

Advanced Settings Before

Press the arrows and choose you desired on both on AC and on battery;

Advanced Setting After

Default buttons behavior

Install dconf-tools:

sudo apt-get install dconf-tools

Press alt+f2 and open dconf-editor (or in a terminal type dconf-editor)

Navigate to org.gnome.settings-daemon.plugins.power and set your default button-power action there:

enter image description here

On some systems you will also need to mark the item suppress-logout-restart-shutdown.

Zanna
  • 72,312
Bruno Pereira
  • 74,715
46

I'm afraid that the first answers didn't work for me, I think that the 'graphical solutions' only work for the upper right indicator, not for the power button. rulet solution works for me, I think I can improve it and make the prompt completely disappear. Instead of creating a new file you can use existing /etc/acpi/events/powerbtn file

sudo -H gedit /etc/acpi/events/powerbtn

Add # to comment line:

#action=/etc/acpi/powerbtn.sh

Add a new line:

action=/sbin/poweroff

Save file. Open a console and type:

sudo acpid restart

That works for me AND the prompt has gone, just like in ubuntu 11.04. Wish this helps.

muru
  • 207,228
33

This is the quick, simple answer I needed:

gsettings set org.gnome.settings-daemon.plugins.power button-power 'hibernate'

If you want to see your settings first, try this:

gsettings get org.gnome.settings-daemon.plugins.power button-power

Or maybe this if you want to see all the power settings:

gsettings list-recursively org.gnome.settings-daemon.plugins.power
Phil Hord
  • 128
13

I wanted to change the power button to suspend-to-RAM. On a Ubuntu 14.04 server (no Gnome/X), changing /etc/acpi/events/powerbtn to use an alternate action (/usr/sbin/pm-suspend) did not work.

Instead, adding a single line to /etc/systemd/logind.conf was enough to do the trick:

#HandlePowerKey=poweroff
HandlePowerKey=suspend

Now, pressing the power button causes instant suspend.

gojomo
  • 181
9

Bruno's answer is only half-correct.

After installing dconf, you should navigate to apps>indicator-session

Place a check mark for the item "suppress-logout-restart-shutdown."

This will work for Unity in Ubuntu 11.10 but not for Gnome 3 or Gnome Classic.

8

That didn't work for me in unity or gnome-shell(prompt was always shown). So I've used this manual

from arch linux wiki. I've created file /etc/acpi/events/power with the content:

event=button/power (PWR.||PBTN)
action=/sbin/poweroff

and executed a command:

sudo acpid restart (don't know exactly if it's right command)

And then by pressing hardware power-button computer shotdowns(the prompt will be shown, but that won't stop shutdown process).

rulet
  • 331
1

For me the solution was was this:

gsettings set org.gnome.settings-daemon.plugins.power power-button-action suspend
1

For current Ubuntu and Lubuntu systems:

echo "HandlePowerKey=suspend" | sudo tee -a /etc/systemd/logind.conf
sudo service systemd-logind suspend
cmcginty
  • 6,016
0

None of this worked on my 13.04 system. In the end I re-compiled gnome-session.

In gsm_shell.c and gsm_logout_dialog.c change #define AUTOMATIC_ACTION_TIMEOUT from 60 to 5