Emulate "Go to Dekstop/Home/etc." behavior in OS X via AppleScript

Posted by pattulus on Super User See other posts from Super User or by pattulus
Published on 2011-02-27T06:34:00Z Indexed on 2011/02/27 7:26 UTC
Read the original article Hit count: 586

Filed under:
|
|

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"
    activate
    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.

© Super User or respective owner

Related posts about osx

Related posts about finder