header image
Blog Menu
Developer
Mr Cryptic
Mr Frenzy
All
Who's Online
We have 8 guests online
Feeds
Home arrow Blog arrow Mr Frenzy arrow Script to Reset Mac OS X Finder Windows
Script to Reset Mac OS X Finder Windows PDF Print E-mail
Written by Joseph Sharp   
Jun 15, 2008 at 01:17 PM

Every so often while working on a project or playing a game in OS X my Finder windows get messed up.  I guess you could say I have a bit of OCD, but I like my Finder configuration. And when it gets changed or messed up it drives me crazy.

I have 2 windows on top that are about half the width of the screen, with 1 window on bottom the full width of the screen.  I use these 3 windows all in column view, which is the most efficient way to navigate the file system.  (This is probably my biggest gripe with Windows—there is no column view.)  This setup allows me to be viewing one or two directories while having a 3rd for moving files around.

 

Finder_ScreenShot

 


When this setup gets messed up I have to fix it.  And since the windows are of different sizes I can't always just make a new window to fill in the gap.  Today I finally decided to write an applescript to fix my finder windows when they get out of whack.  I have decided to share it just in case there is someone out there who will find it useful, or even help them with their own applescript.  I gathered the parts for this script from various places on the Internet.  (Thank goodness for Google.)

Feel free to modify and do whatever you want with the following Applescript.  To use: copy the text into a new Apple Script inside the Script Editor, then save the script as an application or other executable script.

When testing the following script this morning on my Mac with dual monitors... it didnt work since the screen_resolution variable was set to include the width of both monitors put together.

property kDistance : 20
property kDockHeight : 50

tell application "Finder"
    set screen_resolution to bounds of window of desktop
    set screen_width to item 3 of screen_resolution
    set screen_height to item 4 of screen_resolution
    set half_width to (screen_width div 2)
    set half_height to ((screen_height div 2) - (kDistance * 2))
    
    --Close all the old windows
    repeat with i from 1 to count of Finder windows
        close Finder window 1
    end repeat
    
    --Setup 1st Window
    set newWin to make new Finder window
    tell newWin
        set the bounds to {kDistance, kDistance * 3, half_width, half_height}
        set the target to (path to home folder)
        set the current view to column view
    end tell
    
    --Setup 2nd Window
    set newWin to make new Finder window
    tell newWin
        set the bounds to {half_width + (kDistance * 2), kDistance * 3, screen_width - kDistance, half_height}
        set the target to (path to home folder)
        set the current view to column view
    end tell
    
    --Setup 3rd Window
    set newWin to make new Finder window
    tell newWin
        set the bounds to {kDistance, half_height + (kDistance * 2), screen_width - kDistance, screen_height - kDockHeight}
        set the target to (path to home folder)
        set the current view to column view
    end tell
end tell

The following applescript was updated to work with dual monitors.  However, this solution seems hackish to me and doesn't work on all systems the same.  You will need to change the  part that says "Word 6 of" to correspond with the monitor that you wish the script to work with.  Alternately you can set the screen_width and screen_height variables to a static number.

property kDistance : 20
property kDockHeight : 50

tell application "Finder"
set screen_resolution to {word 6 of (do shell script "defaults read /Library/Preferences/com.apple.windowserver | grep -w Width") as number, word 6 of (do shell script "defaults read /Library/Preferences/com.apple.windowserver | grep -w Height") as number}
set screen_width to item 1 of screen_resolution
set screen_height to item 2 of screen_resolution
set half_width to (screen_width div 2)
set half_height to ((screen_height div 2) - (kDistance * 2))

--Close all the old windows
repeat with i from 1 to count of Finder windows
close Finder window 1
end repeat

--Setup 1st Window
set newWin to make new Finder window
tell newWin
set the bounds to {kDistance, kDistance * 3, half_width, half_height}
set the target to (path to home folder)
set the current view to column view
end tell

--Setup 2nd Window
set newWin to make new Finder window
tell newWin
set the bounds to {half_width + (kDistance * 2), kDistance * 3, screen_width - kDistance, half_height}
set the target to (path to home folder)
set the current view to column view
end tell

--Setup 3rd Window
set newWin to make new Finder window
tell newWin
set the bounds to {kDistance, half_height + (kDistance * 2), screen_width - kDistance, screen_height - kDockHeight}
set the target to (path to home folder)
set the current view to column view
end tell
end tell

User Comments

Comment by GUEST on 2008-07-29 09:43:46
I like your OCD. :)

Comment by GUEST on 2008-08-10 15:15:03

Comment by GUEST on 2008-08-16 22:33:05
holy crap! thank you so much! i have been looking everywhere for a solution to my finder problems. you are amazzzing!!

Comment by GUEST on 2008-08-22 17:12:31
"I have decided to share it just in case there is someone out there who will find it useful, or even help them with their own applescript." 
 
Thanks for doing this. I'm finding it very useful already. I'd always use two finder windows, but three finder windows in the configuration you showed makes a heck of a lot more sense! 
 
And it almost completely reduces the need to purchase something like Pathfinder, although there are some bells and whistles there that would be nice in Finder. But that is another discussion! 
 
Thanks again! --Mark 
 


Last Updated ( Jun 16, 2008 at 10:52 AM )