Minimize All Windows of All Applications Other Than The Front Window of the Active Application Macro Needed

I would like to create a macro that minimizes all windows EXCEPT the front window.

@GGLICK and @CCSTONE were kind enough to provide me with macros. I found two macros on the internet as well. They unfortunately do not work because they minimize all windows of the active application except the front window of the active application whereas I want to minimize all windows of all applications except the front window of the active application.

I would very much appreciate assistance with this.

Thank you.

Ah, I see. That is a different task than I initially understood. Okay, this example does not work perfectly, at least on my system, but it should at least get you started:

Minimize All Windows in All Apps Except Front.kmmacros (6.8 KB)

I appreciate that and will give it a go.

So that I am warned, what do you mean by does not work perfectly on your system? What does it do / not do?

It minimizes the windows of many of my running apps, but not all of them, and I haven't yet gotten it to a point where it successfully restores the frontmost window at the time the macro is run. Basically, in its current state, it errors out before it can finish its task, but it does work up to that point.

Ahhh, understood, so the fixes needed are:

  1. Adjust so that it grabs all apps;

  2. Adjust so that it restores the front app of the active application (as presumably it too is initially minimized).

It will give me -- and perhaps others -- something to tinker with.

Thank you!

1 Like

You're welcome, and not exactly. It's grabbing all the apps now, but I think the problem is that it's including menu bar apps or ones without open windows (think launchers like Alfred), and it seems to be getting stalled out in those cases. Once it finishes looping through every app with minimizable windows, it shouldn't have any problem restoring the front window of the active app (though after a little more testing, it looks like the last Manipulate a Window action should be to unminimize the window saved in the first action, rather than bring it to the front) so the only issue I can see is figuring out how to exclude or otherwise handle apps without windows to minimize.

Appreciate the clarification.

An idea is it possible -- to solve the apps in the menu bar option -- to only include apps whose windows are positioned below the menu bar? Does KM have that ability? Would that work?

It may be possible to test for that, but that's above my expertise. One idea I've thought of but haven't tested yet is to keep a list of apps you want the macro to exclude in a separate variable, then search for those app names and remove them from the list of apps the macro is using to loop. If the macro is stalling on apps without windows, that workaround should theoretically let KM sidestep the apps it needs for this to work.

Hmmm, that too should work.

I wonder whether someone can chime in on my idea only because one does not have to maintain a list when one adds / delete applications.

Will work on it too to at least try to contribute. I may even try writing an AppleScript to test for that now that I know I can get it working!

1 Like

Hey Joel,

Here's a tidbit to get you started. I'm not managing the front window of the front app – I'm leaving that as an exercise for the user.

Note – on my old hardware running Mojave this is pretty slow when many windows are open.


# Auth: Christopher Stone
# dCre: 2021/12/13 05:21
# dMod: 2021/12/13 05:21 
# Appl: System Events
# Task: Attempt to Minimize Every Window of Every Application
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @System_Events, @Minimize, @Windows, @Every, @Application

tell application "System Events"
   tell (every application process whose background only is false)
      set appWinList to its windows
   end tell
   repeat with winList in appWinList
      repeat with theWin in winList
            tell contents of theWin
               set value of attribute "AXMinimized" to true
            end tell
         end try
      end repeat
   end repeat
end tell

1 Like

Chris, thanks for this, much appreciated.

I will try to work through it over the next little while and see where I get. I will need to start by learning the System Event dictionary.

It may take a week or two -- super busy at work -- but will be back.

Thanks again.