Habitual wrote:Why kill the browsers if you are shutting down?
Because if you don't close them properly, eventually you will end up with a corrupt browser next time with all inexplicable weirdness which that involves.
@OP
I would suggest a different approach. Instead of killing browsers, which is essentially what shutdown process does, It is better to close their windows using wmctl because it is the same thing as pressing Alt+F4 or clicking on the X button.
Here is what I use as a replacement for shutdown button:
Code: Select all
#! /bin/bash
close_apps () {
WIN_IDs=$(wmctrl -l | grep -vwE "Desktop$" | cut -f1 -d' ')
for i in $WIN_IDs; do wmctrl -ic "$i"; done
# Keep checking and waiting until all windows are closed
while [ "$WIN_IDs" != "" ]; do
sleep 0.1;
WIN_IDs=$(wmctrl -l | grep -vwE "Desktop$" | cut -f1 -d' ')
done
}
close_apps
# Waiting for apps to write what they need prior to their full exit
sleep 3
systemctl poweroff
One more benefit is that in case I have forgotten to save changes in a document open on one of the desktops, it will not shutdown but wait till I do so. In XFCE, in addition to Desktop window, you should not attempt to close the panel because it invokes immediate logout and the script stops(this script is set for Cinnamon). Also, the name of the Desktop varies depending on language used so run
to see what are the names of all running system windows which you should not attempt to close in the close_apps procedure.