To be able to shutdown with a keyboard shortcut we can assign gnome-session-quit ---power-off
to a custom shortcut.
In Unity this will lead to the following dialog:
Then we need another at least two keystrokes to finally power off our system. This is rather inconvenient and I would prefer the old shutdown dialog when you could poweroff by just pressing Return or letting it wait the default countdown of 60 seconds.
When calling gnome-session-quit --poweroff
from a GNOME session flashback session on the same system (14.04 LTS) the old dialog including the countdown comes back:
So we know it dwells somewhere.
Is there any way to call this old dialog when running a Unity session?
Best Answer
Here's a script to emulate the desired behavior. Must be ran as with
sudo
. Can be bound to a keyboard shortcut ( with preliminary addition of theshutdown
command to sudoers file to allow passwordless run ). Simplistic, concise, and does the job.Update: June 14
As suggested by Takkat, here's a script that utilizes zenity's --timer option and dbus to achieve the same behavior without need for sudo access:
Basic idea here is that zenity's timeout option exits with code greater than 0, which typically means command failed. So by treating zenity's cancel option and timeout as the condition that will allow shutdown, we use the OR operator (
||
) to shutdown only if user clicks the cancel button (labeled as "DOIT" ) or dialog times out.Another variation to improve user experience can be done with
yad
(needs to be installed first with these commandssudo apt-add-repository ppa:webupd8team/y-ppa-manager;sudo apt-get update; sudo apg-get install yad
). This variation uses progress bar to let user know how much time is leftAnother possible version, takes into account that if you change zenity's ok button label, the button highlighted by default may or may not be the ok button.
The script shuts down the system upon any return that is not 0. If script times out , the return value of either 1 or 5 tells the script to execute the
else
part