Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have various windows with the same title "MyTitle" across different running applications, which also have other windows with unique titles.

Is there a way I can programmatically cause all of these windows to minimize in an equivalent way to clicking the yellow minimize button?

share|improve this question
add comment

2 Answers

This can likely be done with applescript. I know that you can minimize a single application with this code.

tell application "Safari"
set miniaturized of window 1 to true
end tell 

You can probably select the windows based on their title, you should be able to use the same "set min..." command though.

share|improve this answer
add comment

To go across all applications you will need to enable “GUI scripting” and use System Events.

Open the Universal Access preference pane and make sure “Enable access for assistive devices” is checked.

Then this AppleScript should be close to what you want:

set searchString to "whatever"
tell application "System Events"
    repeat with aWindow in ¬
        (get windows of (application processes whose visible is true) ¬
            whose name contains searchString)
        set aWindow to contents of aWindow
        if aWindow is not missing value and ¬
            (exists attribute "AXMinimized" of aWindow) then ¬
            set value of attribute "AXMinimized" of aWindow to true
    end repeat
end tell
share|improve this answer
    
I get: error "Can’t get attribute \"AXMinimized\" of {}." number -1728 from attribute "AXMinimized" of {} on Mavericks. –  e40 Feb 13 at 11:16
    
@e40: Try changing (get windows of …) to just (windows of …). –  Chris Johnsen Feb 13 at 20:20
    
That worked!! Thanks! I really appreciate it. I'm a noob to applescript and I was banging my head on this one. –  e40 Feb 14 at 0:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.