Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Minimize all Finder windows at login via AppleScript Desktop
I like to leave a few Finder windows open, for easy access to projects I'm working on. However, I don't leave them all visible because they cover the desktop. Minimizing to the Dock is a great solution, except that they don't stay there after logging out. So each time the computer starts up, they're all over the desktop and I have to "option-click" the Minimize button on one of the windows to get them all into the dock.

I wanted to automate this process on login, so after tinkering around with PreFab UI BrowserP, I came up with this little AppleScript:
activate application "Finder"
tell application "System Events"
  tell process "Finder"
    -- GUI Scripting statements:
		
    keystroke "`" using {command down}		
    keystroke "m" using {command down, option down}
		
  end tell
end tell
Enter it in Scrpt Editor, and save it as an Application (Run Only), then add it to your login items. I found that sometimes after logging in, no Finder window had the focus, and that could make the "Minimize All Windows" command not work. So the first keystroke, Command-backtick (Cycle Through Windows), is used to get a focus on one of the windows.

(It would be even nicer if OS X remembered the state of the Finder windows between logins. Interestingly this was also the case in OS 9 -- it too didn't keep windows 'tabbed' at the bottom of the screen between startups.)
    •    
  • Currently 2.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[15,772 views]  

Minimize all Finder windows at login via AppleScript | 16 comments | Create New Account
Click here to return to the 'Minimize all Finder windows at login via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Minimize all Finder windows at login via AppleScript
Authored by: giulio on Jan 02, '07 08:43:09AM

Can you simplify the command keys to just one?
Command-Option-m

---
Freelance web development
WebVeteran.com



[ Reply to This | # ]
Minimize all Finder windows at login via AppleScript
Authored by: giulio on Jan 02, '07 08:44:50AM

I meant... "tell application Finder activate"
That should bring focus to the finder. Then the command-option-m should work.

---
Freelance web development
WebVeteran.com



[ Reply to This | # ]
Minimize all Finder windows at login via AppleScript
Authored by: michelle_eris on Jan 02, '07 08:53:52AM

An even easier way to do this is this one-liner:
tell application "Finder" to set the collapsed of windows to true



[ Reply to This | # ]
Minimize all Finder windows at login via AppleScript
Authored by: Skeeve on Jan 02, '07 09:13:31AM

;-) Better than mine... I started before you posted but then was disturbed for quite a while.



[ Reply to This | # ]
Minimize all Finder windows at login via AppleScript
Authored by: meanbone on Jan 02, '07 12:30:13PM

Yea, this works!
When I was working on this script, I think I found a similar method. However, I didn't like how it closed one window at a time. I thought, that while closing each window, it could interfere with other startup processes or scripts that are firing.

So I settled on the posted solution (command-option-m) since it did all the windows at one time with one command, very quickly.

mb.



[ Reply to This | # ]
Minimize all Finder windows at login via AppleScript
Authored by: n1mie on Jan 02, '07 07:22:38PM

This is a much more elegant solution than the original. I am surprised that you don't need to use the word 'every' in the command somewhere, but it works flawlessly.

Thanks a lot!

---
--Chip



[ Reply to This | # ]
Minimize all Finder windows at login via AppleScript
Authored by: michelle_eris on Jan 03, '07 01:59:08PM

A little known feature of Applescript is that making a plural of something is the same as prepending "every" to it. Therefore, "windows" is the same as "every window". In fact, if you run my script and look in the log, "windows" in the scriopt will be expanded to "every window" in the log.



[ Reply to This | # ]
Minimize all Finder windows at login via AppleScript
Authored by: Skeeve on Jan 02, '07 09:11:40AM
Why not simply:
tell application "Finder"
	repeat with i from 1 to count of Finder windows
		set collapsed of Finder window i to true
	end repeat
end tell


[ Reply to This | # ]
Minimize all Finder windows at login via AppleScript
Authored by: BlakeyRat on Jan 02, '07 07:35:00PM

>>(It would be even nicer if OS X remembered the state of the Finder windows between logins. Interestingly this was also the case in OS 9 -- it too didn't keep windows 'tabbed' at the bottom of the screen between startups.)

Always worked for me... they got borked if you changed screen resolution, but they always stayed put across reboots.

And I'm still pissed at Apple for removing that functionality and not bringing it back. They brought back the useless "Labels" but not the highly useful Tabbed Windows?



[ Reply to This | # ]
Minimize all Finder windows at login via AppleScript
Authored by: meanbone on Jan 02, '07 10:53:46PM

> Always worked for me... they got borked if you changed screen resolution, but they always stayed put across reboots.

You know, your right...
It was "Window Shade" states (full window vs. just window title bar) that didn't get remembered between startups.

Sorry.



[ Reply to This | # ]
Minimize all Finder windows at login via AppleScript
Authored by: UberFu on Jan 20, '07 10:45:50PM

I wished they'd bringg back Tabbed Windows also_ Those were Great_

I have used the color labeling more and mroe ass time goes on_ It works good for coding projects visually for categories such as 'OLD' or "CURRENT' or projects that are 'ON HOLD' waiting for genius clients to figure out what the hell they want_



[ Reply to This | # ]
Minimize all Finder windows at login via AppleScript
Authored by: cxd101 on Jan 03, '07 08:10:05AM

I think that this is a great script! Many thanks - I've been looking for something like this for a long time.



[ Reply to This | # ]
Minimize all Finder windows at login via AppleScript
Authored by: michelle_eris on Jan 03, '07 02:01:01PM

Many of us find labels to be very useful. And minimizing a window to the dock is essentially the same functionality as tabbed windows.



[ Reply to This | # ]
Minimize all Finder windows at login via AppleScript
Authored by: bonobo on Jan 07, '07 03:56:21PM

I also rely on those Labels, but Tabbed Windows were really cool: You could drag stuff into them and they'd pop up, impossible with minimized Windows. But well, now I can drag a window to any screen edge and when I drag something onto it, it moves into the screen space, this is also cool.



[ Reply to This | # ]
Minimize all Finder windows at login via AppleScript
Authored by: UberFu on Jan 20, '07 10:55:45PM

Not Really_

Because if I open up a Folder in the Finder to show me the contents and then I minimize it to the Dock I cannot grab a File from someplace else and drag nad drop it to that opened minimized Folder in the Dock_

If I drag the Closed version of the Folder Icon to the Dock so it's there permanently - I can then drag another File from elsewhere to the Folder Icon located in the Dock and it will move said File to that Folder_ However the Folder still does not expand to reveal the contents [such as the Tabbed Folders Option in OS 9 allowed for]_



[ Reply to This | # ]
Minimize all Finder windows at login via AppleScript
Authored by: zejoao2000 on Jan 02, '10 06:53:20AM
This is my first 2 cents in this forum... Let's see how it comes out.

Taking the core coding option of the first solution by meanbone (using system events to force Minimize All), I came up with this solution to the problem.

-- BEGIN SCRIPT
tell application "Finder"
   activate
   if the (count of windows) is not 0 then
      select Finder window 1
      tell application "System Events"
         tell process "Finder"
            keystroke "m" using {command down, option down}
         end tell
      end tell
   end if
end tell
-- END OF SCRIPT

The if clause tests to see if there are any Finder windows opened. If so, the first one is chosen and "System Events" does the work. If not, nothing happens.

Although there are simpler solutions stated in this thread, I write this one because of the different coding approach to the window selection.
One other advantage of this script is to minimize all the windows in a single step.

Hope it helps someone.
Cheers.
Edited on Jan 02, '10 07:19:37AM by zejoao2000


[ Reply to This | # ]