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.

1 Answer 1

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
5
  • Did you test the script ? Yes = shutdown, No = No.
    – NickTux
    Feb 20, 2014 at 17:40
  • 1
    @NikTh yes I tested it.
    – sourav c.
    Feb 20, 2014 at 17:41
  • 1
    Ha, I didn't comment to you \sourvac\ , but I forgot to mention the user @DKBose ;) . Nice addition by the way (on how to).
    – NickTux
    Feb 20, 2014 at 17:43
  • The bin/ "exportation" included already in .profile
    – NickTux
    Feb 20, 2014 at 21:42
  • @NikTh Yes you are correct. I just checked it. Thanks. I edited accordingly.
    – sourav c.
    Feb 21, 2014 at 2:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .