Just wondering if there is a way to retrieve open windows and minimize them from the command line in Lion?

I have an AppleScript that does this, but it kind of slow, so wanted to know if there was anything


EDIT: I have not completely figured out how to do it yet, but there is the command line command osascript which allows you run applescript from the command line. So you can use:

osascript -e "applescript command goes here"

SOLVED: Yes you can do it... here is how I figured it out:

/usr/bin/osascript -e 'tell application "System Events" to click (first button of (every window of (application process "firefox")) whose role description is "minimize button")'

Some other application process that I have are "Skype", "Finder", "thunderbird-bin", AppleScript Editor"

  • 1
    Any command line solution would have to use the same Apple Events as the script (the Apple Events are used to talk to the applications to tell them to minimize your window), so it's likely to be just as slow...
    – Michael Dautermann
    Dec 26, 2011 at 20:16
  • 1
    Why not use keyboard shortcuts?
    – Jaypal Singh
    Dec 26, 2011 at 23:20
  • I have other processes "System Events" , "Finder", "System Preferences", "Terminal" for which it works perfectly fine. But doesn't work for any of the browsers, I have tried all combination "Firefox", "Mozilla Firefox", "firefox", "Firefox.app", "Mozilla Firefox.app", "firebox-bin" Jul 16, 2019 at 7:20
  • I have "Brave Browser" as well, Interestingly for it the correct message (ie button 3 of window ...) comes only when already minimised but when it is restored to normal size it says missing value. Same for "Google Chrome" Jul 16, 2019 at 7:35

1 Answer 1


I agree that pretty much any solution you can get for the command line would have to rely on AppleScript. And your solution will work. However, rather than scripting System Events, which depends on UI events (actually moving your mouse and clicking) it's a much cleaner approach to script the application's window directly.

This way, if you move your mouse while the script is executing, it won't affect it. For minimizing all Firefox windows you could do something like:

tell application "Firefox" to set miniaturized of every window to true

The property is called miniaturized for Firefox and most OS X applications, but some third-party apps, like Google Chrome, call the property minimized, so if one doesn't work, the other should. This functionality is part of the Standard Suite that pretty much every AppleScript-able application has.

For applications that don't support AppleScript at all, you can fall back to your approach and use System Events to access the windows belonging to the application's specific process running on your machine.

If I were you, though, I'd try to rely on the application to minimize itself rather than through System Events where possible, as this will be much more reliable.

  • not working. throwing error 33:36: syntax error: Expected end of line but found “set”. (-2741) Jul 16, 2019 at 7:41
  • 1
    I want to minimise Spotify but neither miniaturized nor minimized work. Both return error 30:67: execution error: Spotify got an error: Can’t make minimized of every window into type specifier. (-1700)
    – Matt Canty
    Oct 30, 2019 at 10:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .