how do I open a folder using Applescript?

How do I tell Applescript to open folders? For example how would I open the Documents folder?
Thanks

Mac, Mac OS X (10.6.2)

Posted on Feb 2, 2010 8:32 PM

Reply
8 replies

Feb 2, 2010 8:35 PM in response to Ronan

<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #ADD8E6;
overflow: auto;"
title="this text can be pasted into the Script Editor">
tell application "Finder"
open (path to documents folder)
end tell</pre>

Feb 2, 2010 9:09 PM in response to Ronan

read the applescript guide that kappy linked. this is NOT how you specify paths in applescript. you can do it as I did in my example. there are other ways too. you can do this
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #ADD8E6;
overflow: auto;"
title="this text can be pasted into the Script Editor">
tell application "Finder"
open ("/Users/macbook/Documents" as POSIX file)
end tell</pre>

Feb 4, 2010 8:45 PM in response to Ronan

Ronan wrote:
Hi, Thanks..

I tried

tell application "Finder"
open ("/Users/macbook/Documents" as POSIX file)
end tell

and got this:

Finder got an error: AppleEvent handler failed.

this means that you are using wrong username. i assumed from your previous post that macbook was your username. what you should put there instead of macbook is your short user name which is the same as the name of your home directory.
any ideas?

Feb 5, 2010 2:11 AM in response to Ronan

In the first example, V.K. didn't mean for you to fill in "path to documents folder" but to actually copy that exact script.
path to documents folder
is a valid Applescript statement. You can get a 'path to' various default folders using that command and the correct form of the special folder name.

In Applescript, paths are delimited with the colon ( : ). So, the path to user macbook's documents folder that is stored on the hard drive named "Macintosh HD" is "Macintosh HD:Users:macbook:Documents"

In the second example, V.K. used the POSIX path method which allows use of unix-style paths.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

how do I open a folder using Applescript?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.