5

I have an AppleScript that I would like to be able to use from anywhere in the file system. Currently, it has some paths which are hardcoded, so it runs only from the Downloads folder. How should I go about getting the current path to the AppleScript and then appending a subdirectory to that path once obtained?

Setting the current path to the script as a variable would be preferable (perhaps current_path).

10

You can get the path of the current script with path to me. Extracting the path to the directory containing the script is slightly tricky:

tell application "Finder"
    set current_path to container of (path to me) as alias
end tell
  • 2
    If posix path is needed add the following command before end tell : set p to POSIX path of current_path – Marc_Alx Dec 6 '17 at 10:27
  • 1
    This worked for me to get the app's path and append a subdirectory; set current_path to (POSIX path of (container of (path to me) as alias)) & "subdirectory/" – jgraup Jan 16 '18 at 21:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .