Minimize all windows on Mac OS

AppleScript to quickly minimize every window on my macOS. This is not hiding the windows, but minimizing them on the dock.

I have the issue that I tend to keep plenty of windows open on my Mac. This issue persists until my next reboot, but in some cases, I just get overwhelmed by all the mess. Unfortunately, there is no built-in feature for macOS to minimize all windows at once. But there is a simple way to do it with AppleScript.

The script

You can use this AppleScript to minimize all windows. You might get asked for accessibility permissions the first time you run it.

1tell application "System Events"
2  set theProcesses to (every process whose visible is true and name is not "Finder")
3  repeat with proc in theProcesses
4    tell proc
5      set theWindows to every window
6      repeat with win in theWindows
7        set value of attribute "AXMinimized" of win to true
8      end repeat
9    end tell
10  end repeat
11end tell
12tell application "Finder" to set collapsed of windows to true
13

As I am an Alfred user, I created a small workflow to execute this via Spotlight. You can download it here. Also check out my Alfred VS Code extension.

Other solutions

I stumbled upon this superuser thread asking for the same thing. The answers point out the exposé and the Command+Option+H+M key combo. The later one unfortunately doesn’t work for me, as it only hides the windows without them appearing in the dock as minimized windows.