Gracefully Closing Programs Redux

Chasing little paper cuts and quirks is ongoing since adopting KDE 5. One of those quirks is when quitting a VPN client session, the respective shell script sometimes failed to close Firefox.

Digging deeper found the Alt+F4 keyboard shortcut from xdotool did not always succeed. The failure was not repeatable.

The original shell script was modified to include a second check. If the target software remained active then use the more unforgiving Ctrl+q:


    Terminate_Internet_Apps () {
    WID="$(xwininfo -root -tree | grep "$1" | awk ‘{print $1}')"
    if [ "$WID" != "" ]; then
      MSG="Attempting to close $1 (window ID $WID) with Alt+F4"
      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
      sleep 1
      WID="$(xwininfo -root -tree | grep "$1" | awk ‘{print $1}')"
      if [ "$WID" != "" ]; then
        MSG="Attempting to close $1 (window ID $WID) with Ctrl+Q"
        Popup_Message
        xdotool windowactivate --sync "$WID"
        sleep 1
        xdotool key --clearmodifiers ctrl+q 2>/dev/null
        EXIT_CODE="$?”
        MSG="Exit code: $EXIT_CODE"
        Popup_Message
      fi
    fi
    }
    

Why the sledge hammer is sometimes needed only with Firefox is unknown. The problem seems limited to KDE and not other desktop environments.

Posted: Category: Usability Tagged: KDE

Next: The Downhill Slide of DuckDuckGo

Previous: Lightning Calendar Data — 2