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

Create a 'parent directory' Toolbar button Desktop
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...]
    •    
  • Currently 3.43 / 5
  You rated: 5 / 5 (7 votes cast)
 
[20,000 views]  

Create a 'parent directory' Toolbar button | 22 comments | Create New Account
Click here to return to the 'Create a 'parent directory' Toolbar button' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create a 'parent directory' Toolbar button
Authored by: Puzo on Jul 27, '05 09:58:50AM

View > Customize Toolbars... > Path
This Path icon will allow you to go to parent directory. And any grandparent directory, for that matter. Sure, it's drop-down, not true "one click" - is that what bothers you?



[ Reply to This | # ]
Create a 'parent directory' Toolbar button
Authored by: thoughton on Jul 27, '05 03:01:53PM

You can achieve the same thing buy command-clicking the folder's name at the top of the folder window.



[ Reply to This | # ]
Create a 'parent directory' Toolbar button
Authored by: CaptDeuce on Jul 27, '05 04:35:17PM

People, the issue is not simply how to show the parent folder but to do so with a single click of the mouse. The standard is much more complex: key press, scroll, and select. Column view is no better since clicking on the left scroll arrow won't necessarily reveal the entire parent directory.

This capability existed in Standard File Dialog Box from a very early System, definitely pre version 6 through Mac OS 8 or so. I really, really miss it.

If you'll excuse me, I'm gonna install that script ...

---
--
"Where's my other sock?" - A. Einstein

[ Reply to This | # ]

Create a 'parent directory' Toolbar button
Authored by: macsolve on Jul 27, '05 10:15:16AM
Or put simpler as a one-liner:

tell application "Finder" to open container of target of front window


[ Reply to This | # ]
Create a 'parent directory' Toolbar button
Authored by: cfoster on Jul 27, '05 12:07:23PM

Yep, that's pretty good. Though it does open a new window instead of changing the directory in the current window, and gives an error when we're at the root. The following exhibits the same behaviour as the original script:

    try
	tell application "Finder" to set target of front window to ¬
		container of target of front window
    end try

Hope this is helpful.



[ Reply to This | # ]
Create a 'parent directory' Toolbar button
Authored by: drmoomoo on Jul 28, '05 12:16:10AM

Thanks for that cleanup. Like I said in the tip, I'm new to Applescript (and writing any code in general) and spent a good half hour trying to figure out that root folder crash. That's how I ended up with so many lines. Never thought of a try statement. *sheepish grin*



[ Reply to This | # ]
Create a 'parent directory' Toolbar button
Authored by: capitalj on Jan 01, '06 09:08:10PM

Thank you cfoster, I gave your script an iTunes-like back button and put it in my tool bar.



[ Reply to This | # ]
Create a 'parent directory' Toolbar button
Authored by: SimonDorfman.com on Jul 27, '05 10:23:53AM

You can also just control-click on the folder icon at the top center of the finder window to go up any number of levels.



[ Reply to This | # ]
Create a 'parent directory' Toolbar button
Authored by: jctull on Jul 27, '05 11:14:41AM

Command-click for me



[ Reply to This | # ]
Umm…CMD-Click Titlebar?
Authored by: jscotta on Jul 27, '05 10:24:24AM

First, I am assuming we are talking about the Finder. If that is true, then why not just command-click on the menu title and get an entire path to choose from. Better yet, use Column View. It is so much better than a toolbar method or Windows Explorer for quickly traversing a file system.

---
Windows because I have to. OS X because I want to.



[ Reply to This | # ]
Create a 'parent directory' Toolbar button
Authored by: Micah_Gideon on Jul 27, '05 10:24:43AM

If you option-click the folder name in the title bar, it pops up the path back to the root directory and you can select any one in between.  Is this not sufficient?



[ Reply to This | # ]
Create a 'parent directory' Toolbar button
Authored by: bgagnon on Jul 27, '05 10:26:05AM

that would be Command-Click, not Option-Click



[ Reply to This | # ]
Create a 'parent directory' Toolbar button
Authored by: latelio on Jul 27, '05 11:00:24AM

I think the easiest way is COMMAND + ARROW UP,

(COMMAND + ARROW DOWN will open folders, files or application). Very handy!



[ Reply to This | # ]
Create a 'parent directory' Toolbar button
Authored by: zane on Jul 27, '05 06:18:09PM

Agreed. It couldn't really be any simpler than "Command/Apple+Up Arrow".



[ Reply to This | # ]
Create a 'parent directory' Toolbar button
Authored by: CaptDeuce on Jul 28, '05 11:07:48PM

It couldn't really be any simpler than "Command/Apple+Up Arrow".

How about leaving you hand on your rodent, moving the pointer and clicking? Keyboard only solutions are at least as bad as mouse only solutions. Complex mouse or keystroke aren't any better.

---
--
"Where's my other sock?" - A. Einstein

[ Reply to This | # ]

Create a 'parent directory' Toolbar button
Authored by: michaelj on Jul 27, '05 11:47:10AM

As the others have mentioned - Command click on the folder icon at the top of the window to see the full path. Not Conrol click or Option click - these do nothing.



[ Reply to This | # ]
Create a 'parent directory' Toolbar button
Authored by: crazyapplerumors on Jul 27, '05 04:43:25PM

[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...]

Actually this functionality has been built into os x for as long as I can remember. In the finder, go to the View menu and select "Customize Toolbar". In the window that drops down you will see an item called path, that you can drag to the toolbar. Presto.

Now just click on path anytime you want to go to the parent folder or above.



[ Reply to This | # ]
Create a 'parent directory' Toolbar button
Authored by: cbthomas on Jul 27, '05 05:38:55PM
If you replace the generic script icon with the right style of icon (like this, for instance), it will look like a button when you place the script in your toolbar. The style doesn't quite match in this example, but it's not bad.

[ Reply to This | # ]
Create a 'parent directory' Toolbar button
Authored by: guardian34 on Jul 27, '05 06:00:00PM
I made a script a while ago that moved files "up" to their parent folder. I changed it so you can also use it to change the current folder (just like the hint). Then, I slapped a little icon on it (I'm not an artist) and posted it here. I hope someone finds it useful.

[ Reply to This | # ]
[sigh]
Authored by: designbot on Jul 27, '05 07:18:15PM

Windows people.



[ Reply to This | # ]
Create a 'parent directory' Toolbar button
Authored by: gaylward on Jul 28, '05 08:18:36AM

"Customize toolbar" from the Finder's view menu allows you to drag a "path" button onto the toolbar. This shows a complete path similar to command clicking on the window title, but without even having to press a modifier key. Surely this completely addresses the problem?!

Bill Aylward



[ Reply to This | # ]
Create a 'parent directory' Toolbar button
Authored by: dave_williams on Jul 28, '05 10:28:24AM

Take a look at Finder substitute PathFinder at http://www.cocoatech.com/

Amongst its standout features is a path bar conveniently located right above the active window. Use it constantly to navigate around.



[ Reply to This | # ]