MacOS – Get Current Path to Script within AppleScript and Append Subdirectory

applescriptmacos

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).

Best Answer

  • 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
    
  • Related Question