Minimize all Finder windows at login via AppleScript

Jan 02, '07 07:30:00AM

Contributed by: meanbone

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.)

Comments (16)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20061228162454404