Gracefully Closing Programs
In my ongoing efforts with learning to use a VPN client, I wanted a method of closing key internet programs. Somewhat like a VPN kill switch. The software I wanted to close included Firefox, Thunderbird, and QuiteRSS.
None of those three programs closed gracefully with kill -SIGTERM
. Instead all three abruptly terminated.
The little problem turned out to be a challenge.
To my original shell script wrapper that manages my ProtonVPN connection I added a function to gracefully close affected software. I used the xwinfo
command to obtain a window ID. I used xdotool
to activate the window and send the Alt+F4
keyboard shortcut to close the window. The function snippet looks like this:
Terminate_Internet_Apps () { WID="$(xwininfo -root -tree -int | grep "$1" | awk ‘{print $1}')" if [ "$WID" != "" ]; then MSG="Attempting to close $1 (window ID $WID)" Popup_Message xdotool windowactivate --sync "$WID" sleep 1 xdotool key --clearmodifiers alt+F4 2>/dev/null EXIT_CODE="$?” MSG="Exit code: $EXIT_CODE" Popup_Message fi }
The snippet works well.
Posted: Usability Tagged: General
Category:Next: VirtualBox Snapshots With Raw Disk Access
Previous: Updating Slackware — 5