15
votes

I m trying to open a folder in Finder using AppleScript. The following is my code. I want the folder WorkSpace to open in Finder, but it opens the Parent Folder /Volumes/MyMacDrive/Mani and highlights the WorkSpace folder. I want the contents of WorkSpace folder, but all I'm getting is its Parent Folder's Contents. What am i missing here ..?

property the_path : "/Volumes/MyMacDrive/Mani/WorkSpace/"
set the_folder to (POSIX file the_path) as alias
tell application "Finder"
    activate
    if window 1 exists then
        set target of window 1 to the_folder
    else
        reveal the_folder
    end if
end tell
3
Use the Finder window class instead of window to not have an error if one of these windows is open (information window, preferences window, clipping window and view options window).--> if Finder window 1 exists then . The reveal command : Bring the specified object(s) into view, use the open command as in adayzdone's answer.jackjr300

3 Answers

23
votes

As far as I've searched, there seems to be no way to open the folder rather than just highlighting the folder in AppleScript. So I have used:

do shell script "open /Volumes/MyMacDrive/Mani/WorkSpace/"

It worked fine for me but please update me if i'm wrong.

18
votes

It's actually simpler than it seems:

tell application "Finder" to open ("/Volumes/MyMacDrive/Mani/WorkSpace/" as POSIX file)

or use colons to give an AppleScript path:

tell application "Finder" to open "MyMacDrive:Mani:WorkSpace"

with that you have an open window

4
votes

Try:

if front Finder window exists then
    set target of front Finder window to the_folder
else
    open the_folder
end if

Edited to incorporate jackjr300's correction. Finder window is the correct class to use.