8 Replies Latest reply: Feb 5, 2010 2:11 AM by Barney-15E
Ronan Level 2 Level 2 (150 points)
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)
  • V.K. Level 9 Level 9 (56,130 points)
    <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>
  • Kappy Level 10 Level 10 (252,460 points)
    You should start with The AppleScript Language Guide.
  • Ronan Level 2 Level 2 (150 points)
    I tried this:

    tell application "Finder"
    (open) / Users / macbook / documents
    end tell

    When I compile, Applescript adds the commas to open and puts spaces around the slashes.

    I get this error: Finder got an error: Handler can’t handle objects of this class.
  • V.K. Level 9 Level 9 (56,130 points)
    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>
  • Ronan Level 2 Level 2 (150 points)
    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.

    any ideas?
  • baltwo Level 9 Level 9 (61,945 points)
    Post to the AppleScript forum under OS X Technologies.
  • V.K. Level 9 Level 9 (56,130 points)
    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?
  • Barney-15E Level 8 Level 8 (41,395 points)
    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.