My girlfriend's cat was walking on my laptop, and I didn't notice her. When I turned to check, I see that I have 32 "Archive Manager" tabs. How can I close them all instantly, as if using Alt+F4 on all of them at once.
My girlfriend's cat was walking on my laptop, and I didn't notice her. When I turned to check, I see that I have 32 "Archive Manager" tabs. How can I close them all instantly, as if using Alt+F4 on all of them at once.
From command line:
You can do alt+f4 but you need to do that for every archive manager that was opened.
Another approach would be to use the
wmctrl
utility (Window Manager control). This can be used to tell the window manager to pretend you clicked the close button. This avoids the potentially heavy-handed nature ofkillall
; for example, some programs with an unsaved document will immediately exit when they are killed (even gently), while clicking the close button brings up a "Do you wish to save?" prompt.The basic command is
wmctrl -c WINDOWTITLE
, so in this casewmctrl -c "Archive Manager"
(assuming it has no open file: that changes the title). Unfortunately, it only closes one at a time, so we need to do more to close all of them.wmctrl
returns success if it finds a match, so we can loop until it fails:This always chooses the first window it finds, so we need to sleep for a bit to avoid continuously sending a stream of close commands to the first window that's already busy closing - that can cause an error which stops the loop.
This is simple and usually works, but sleeping a set amount of time and hoping a window closes before we try again is a messy and slow way to avoid the error. What we really want to do is to immediately send one close message to every matching window.
We can find all open windows with
wmctrl -l
. This lists a numeric window id that we can use to identify each window individually, even if they all have the same title. Then we need to filter to only the matching windows (thegrep
command), pull out just the window id (thecut
command) and callwmctrl -i -c
for each one. The-i
is needed to match the window id instead of the window title.A bit complicated for just typing in whenever a cat steps on your keyboard, but hopefully a handy technique to keep in your scripting toolbox.
You can use the Ctrl+Q keyboard shortcut which will close all opened windows of Archive Manager.
The Ctrl+Q shortcut is common on Ubuntu (and lots of other distributions as well). It works the same with most of the applications I've used thus far. That is, it will close all windows of a running application.