1

When I press the hardware power button and the login screen (or unity) is running I get a nice "are you sure you want to shutdown" message.

When I am running fluxbox, I get a software shutdown, but no message/confirmation.

Is there any way to change that? I don't mind writing the zenity script/program, I just need a place to put it.

josinalvo
  • 6,947
  • 5
  • 37
  • 51
  • 1
    Please see if https://askubuntu.com/questions/423757/confirm-shutdown-with-zenity helps. Even though it's from 2014, it works for me in the Openbox session of Lubuntu 16.04. – DK Bose Jul 04 '18 at 03:43
  • Thanks, but I think it answers a different question. I am not asking how to write a shutdown program. I am asking where can I put a shutdown program, so that, when I press the power button, the program runs – josinalvo Jul 04 '18 at 04:07
  • did I misunderstand your link? – josinalvo Jul 04 '18 at 04:07
  • No, you got it right. I don't use the power button. To change what the power button does would probably involve deeper coding knowledge. So what I've suggested is a workaround for when you're in a Fluxbox session. If you log into the default, the power button would still work as you describe it does by default. – DK Bose Jul 04 '18 at 04:16

1 Answers1

1

From: Fluxbox Wiki - Shutdown computer with dialog

Fluxbox doesn't come with some nice eye candy way to shutdown your computer. But, if you're using GDM to log in, you can also tell it to shut down. For ease of use, a script giving you some confirmation dialog can be used.

First, we'll create a dialog:

xmessage -nearmouse -buttons No:1,Yes:0 "Really shutdown?"

There are other ways to do this, we're not bound to use xmessage here. It's an easy way, though.

If the user clicks the "no" button, nothing else needs to be done, except maybe giving him some advice on using his mouse. If he clicks on "yes", we'll shut down his computer.

To do so, we'll first tell GDM that we want to shutdown by the time fluxbox exits:

gdmflexiserver -a -c 'SET_LOGOUT_ACTION HALT'

Then, we kill fluxbox:

kill -TERM $(xprop -root _BLACKBOX_PID | awk '{print $3}')

Some string and tape adds up to a script to add to your menu:

#!/bin/sh
if xmessage -nearmouse -buttons No:1,Yes:0 "Really shutdown?"; then
  gdmflexiserver -a -c 'SET_LOGOUT_ACTION HALT'
  kill -TERM $(xprop -root _BLACKBOX_PID | awk '{print $3}')
else
  xmessage -nearmouse "Then why did you press that big red button?"
fi

Caveat: I don't use Fluxbox. Any clarifications on material on their Wiki page will have to be asked to them. I've cleaned up some of the grammar after copying their website instructions above, but it's still not perfect.


You can find a rather heated argument about the "Shutdown Button" between a user and Fluxbox (developers?) on Source Forge. At the end of the argument someone posts source code and it appears /usr/bin/shutdown might be where you want to put in the hook. ie Create your own /usr/bin/shutdown which calls /usr/bin/shutdown2 which is the original copy.

  • My question is not how to make a script to ask nicely for shutdown, but rather about how to make such a script run when the power button is pressed – josinalvo Jul 11 '18 at 15:00
  • That's what the developers are talking about in the links I think. Also I added my own point about shutdown hook but that might interfere with ststemd. – WinEunuuchs2Unix Jul 11 '18 at 15:07