Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

OS X has build in support for going to certain Folders (Home, Utilities, Desktop, etc.) via a Shortcut.

I wanted to emulate this behavior for the the Downloads Folder. The only thing that is missing the script below is that it won’t succeed when no window is opened in the Finder (see Error message).

tell application "Finder"
    set target of Finder window 1 to folder "Downloads" of folder "username" of disk "Macintosh HD"
end tell

Error message:

error "Finder got an error: Can’t set Finder window 1 to folder \"Downloads\" of folder \"username\" of disk \"Macintosh HD\"." number -10006 from Finder window 1

It great if you know about some kind of 'if-compliement' that triggers opening the Downloads Folder in case there is no window 1 open in the Finder. Thanks in advance.

share|improve this question
up vote 1 down vote accepted

I would simply use an open statement as follows, exploiting the fact that the Finder already knows what home means:

tell application "Finder"
    open folder "Downloads" of home
end tell

which will create a new window showing the Downloads folder or bring any window currently showing the Downloads folder to the front.

share|improve this answer
Thanks for the answer. – pattulus Feb 27 '11 at 9:38

The Go menu items open a new window if none is open yet. So to get the same behavior:

tell application "Finder"
    if (count of windows) is equal to 0 then
        open folder "Macinthosh HD:Users:yourname:Downloads"
        set target of (first window whose index is equal to 1) to folder "Macinthosh HD:Users:yourname:Downloads"
    end if
end tell

This doesn't work if you use FileVault though. You can always use a path relative to your home folder using

folder "Downloads" of home

as @Asmus suggested.

share|improve this answer
Thank you very much for this answer, it was very useful to understand the if/else part. I guess this will be very useful in some other scripts that I try to setup now. – pattulus Feb 27 '11 at 9:40

set target is pretty annoying to use in column view though. It includes every column starting from the root, even if some of the containing folders were in the sidebar.

I use something like this myself:

tell app "Finder"
    set p to path to desktop
    close every window
    open folder p
    set w to window 1
    set toolbar visible of w to false
    set current view of w to column view
    set bounds of w to {0, 22, 960, 589}
end tell

And for example ⌥A opens /Applications.

It doesn't really emulate those default shortcuts, but there are a few advantages:

  • You can use global shortcuts, a bit like with Quicksilver triggers
  • It restores the default bounds (like Finder Minder)
  • You can make sure that the window opens with your preferred view options
  • IMO it's better to have just a single Finder window open at a time, so this sort of enforces it
share|improve this answer
Wow! That’s also a very nice script. Often I need several windows open when I'm sorting out stuff. This script will enables me to easily clean up the mess I’ve made with all that open finder windows and focus on one window - this will sure come in handy. Thank you l-ri! – pattulus Feb 28 '11 at 5:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .