Is it possible to configure this action to close all windows of the front app?
You didn't say which app. But you should try OPT-CMD-M which seems to do that in any app that supports this standard shortcut.
Some apps have a "Minimize All (Windows)" function under the Window menu item. Did you check for that? Like the KM Editor, for example. You could even create a KM action that selects this menu item in the current app.
You did say "close" all windows, but I presume you meant "minimize" all windows instead. Closing all windows would require special handling in many apps (like saving files.) And you can close all windows in most apps by quitting the app. So this is why I'm assuming you meant "minimize," instead of "close." Is my assumption correct?
Assuming you did mean close, I use Applescript for this because I found it the more reliable solution for my purposes, specifically with Finder, though it should be generally applicable.
Thanks for your reply @Airy. I confirm that I was asking for a KM action to close all windows.
It would be useful for apps like "BetterTouchTool" or "Stream Deck", that run in background when their windows are closed but they run in foreground when any of their windows are opened.
Furthermore, this kind of apps can have opened 1, 2 or 3 opened windows, so an action tp close all the windows would be useful.
Thanks for the applescript @hemicyon, but I would prefer to not use an applescript and do it with KM action/s.
In that case, you'll need do something like get the window count and wrap the close action inside a repeat:
[edit] I always forget you can do calculations in a lot of action fields, no variable necessary.
There are probably other KM-only methods; this is just the first that comes to mind. I had consistency/reliability issues using something similar for Finder inside other larger macros, which is why I went the Applescript route.
I apologize for misconstruing your request.
I'll note that there's a chance, albeit slim, of new windows being opened while the others are being closed -- because you are only closing a certain number of windows there may be "leftovers".
This is the ideal place for a "While" action, IMO:

Let's not forget that the Finder considers the Desktop a window that cannot close. So this may take a "While"
Ah, perhaps this is part of the reason why I've found Applescript to be more reliable with Finder for this purpose.
Hmm..I tried to find some clever way to do something like this (which clearly does NOT work):
But that seems a dead end. Only sharing because we have some pretty clever friends around here...




