0

I'm trying to launch a Finder window of a folder that's in the same directory as my script. When I run the code below, it launches a blank Finder window set to the path of the script not to the folder.

tell application "Finder"
    tell application "Finder" to make new Finder window
    set file_path to (path to me) as text
    set target of Finder window 1 to file_path
end tell

How can I get the path to the folder of the script, not the script?

1

2 Answers 2

2

You were close. You do not need the text version of the file, you only need the file itself, then you can ask Finder for that file's container:

tell application "Finder"
    tell application "Finder" to make new Finder window
    set file_path to (path to me)
    set target of Finder window 1 to file_path's container
end tell
Sign up to request clarification or add additional context in comments.

Comments

1

The shortest way I know to do this is:

tell application "Finder" to open ((path to me as text) & "::")

Editing your script renders the following:

tell application "Finder"
    make new Finder window -- There is no need for an your second tell statement
    set file_path to (path to me as text) & "::" -- Goes up one directory
    set target of Finder window 1 to file_path
end tell

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.