wmctrl
may help you (package name wmctrl
).
wmctrl
helps you interact with a EWMH/NetWM compatible X Window Manager. I'm not sure is AwesomeWM fits this description, but if it does, this answer would work.
$ wmctrl -l
0x0100002d 1 stewbian arch linux - How to reboot/shut down gracefully in Awesome WM? - Unix & Linux Stack Exchange — Mozilla Firefox
0x01200007 0 stewbian ~ : bash — Konsole
$ wmctrl -c 0x01200007
This could be scripted to list all windows (wmctrl -l
), iterate over the list, and close each (wmctrl -c
). When that is done, then shut down.
#!/bin/bash
wmctrl -l | awk '{ print $1 }' | while read -r windowid; do
wmctrl -c $windowid
done
shutdown -h now
If that doesn't work, wmctrl
can get a PID of the parent process, where you could send a signal (kill
) to each PID.
#!/bin/bash
pids=$(wmctrl -lp | awk '{print $3}')
kill -SIGTERM $pids
sleep 2
pids=$(wmctrl -lp | awk '{print $3}')
kill -SIGKILL $pids
sleep 2
shutdown -h now
You could also split this by processes. You could send SIGTERM to windows with Firefox in the titlebar, but SIGINT to instances of QtCreator, then SIGABRT to everything else including Firefox and QtCreator if they still exist.
#!/bin/bash
pids=$(wmctrl -lp | awk '/Firefox/{print $3}')
kill -SIGTERM $pids
pids=$(wmctrl -lp | awk '/Qt Creator/{print $3}')
kill -SIGINT $pids
sleep 10
pids=$(wmctrl -lp | awk '{print $3}')
kill -SIGABRT $pids
shutdown -h now
ksmserver
and invoking its power off shortcut using dbus?ksmserver
is the kde session management server, which takes care of graceful logouts/shutdown in the kde desktop. what i suggested is running it in your user session so it already adds the kde session management shortcuts, such as ctrl-alt-del or the power button.