Create a 'parent directory' Toolbar button

Jul 27, '05 09:09:00AM

Contributed by: drmoomoo

One of the few things I like about Windows that I thought OS X was sorely missing was a Parent Directory button (a button that opens the folder containing the folder the current window is showing). So I created an Applescript application that can be put on the toolbar to do the same thing. Here's the code:

tell application "Finder"
  set fdir to the target of front window as text
  set fname to the name of front window as text
end tell
set AppleScript's text item delimiters to {""}
set x to (length of fname) + 2
set fdir1 to characters 1 thru -2 of fdir as string
if fdir1 is not fname then --is current window at root of hd?
  set up1 to (characters 1 thru -x of fdir) as string
  set AppleScript's text item delimiters to {" "}
  tell application "Finder"
    set target of front window to up1
  end tell
end if
I also zipped the script's source code and the compiled application into a 22KB archive if you want to try them the easy way. This is my first time using AppleScript, so it's probably a bit rough (and it only has the standard AppleScript icon).

[robg adds: There's a built-in "show parent folder" command in the Finder; Go -> Enclosing Folder, or Command-Up Arrow. But as far as I can tell, there's no simple method to get that command into a toolbar button (but I am far from an AppleScript expert). You could use UI scripting to select that menu item, but that seems like more work than the above solution...]

Comments (22)


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