Search code examples
stringapplescriptsubdirectory

How to trim strings in AppleScript?


I am trying to trim a returned string in AppleScript. It's the directory of the script within the app I packaged it in. The idea is to make this app mobile as the old one relied on a static directory to run a script within another app, Spore_origin.app, contained within it's app package. Here's the code:

to run
    set current_path to POSIX path of (path to me) as string    
    tell application "Terminal"
        do script current_path & "/Spore_origin.app/Contents/MacOS/cider_noui"
    end tell    
end run

What I want to do is trim this off the end:

/Users/mypetnamedsteve/Stuff/Spore.app/Contents/Resources/Scripts/main.scpt

The Highlighted bit needs trimming but I don't know how. HeLp!!!!


Solution

  • Just get the parent folder. No need to use string manipulation

    set current_path to (POSIX path of (container of (path to me))) as string
    

    depending on the type of path - if you get a hfs path this will also work

    set current_path to POSIX path of ((path to me as text) & "::")