6

I got this command which enables me to shutdown Ubuntu 13.10 directly from the keyboard (without needing to open a terminal and running something like sudo shutdown -h now):

dbus-send --system --print-reply --dest=org.freedesktop.ConsoleKit /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop

I have bound this command to a shortcut: CtrlAlt` and it works.

However, I want to know if I can get a Zenity window which will run the above shutdown command if I type y as a response; but if I press n the Zenity window should close and I can continue with my session.

DK Bose
  • 42,548
  • 23
  • 127
  • 221

1 Answers1

8

You can use the following script,

#!/bin/bash

zenity --question --text="Are you sure, proceed to shutdown?"
if [ $? = 0 ]; then
    dbus-send --system --print-reply --dest=org.freedesktop.ConsoleKit /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop

else
    exit
fi

Usage

save the script as shutdown.sh. Give it execution permission as,

chmod +x shutdown.sh

To shutdown use,

./shutdown.sh

You will get the following notice from zenity

enter image description here

keyboard shortcut

you can set custom keyboard shortcut for the script from System settings >> Keyboard >> Shortcuts >> Custom shortcut In the field command use,

/path/to/shutdown.sh  

From terminal

Create a folder bin in your home. check if it is in your PATH,

echo $PATH

If you can not see it in your path, make it available in path. You can use following commands in your terminal for this,

cd
mkdir bin
echo -e "\nexport PATH=\$HOME/bin:\$PATH" | tee -a ~/.bashrc
. ~/.bashrc

Put shutdown.sh in bin folder. Then you will be able to access the executable from terminal as,

shutdown.sh
sourav c.
  • 44,715