2017-07-18 181 views
0

我想修剪AppleScript中返回的字符串。这是我打包的应用程序中的脚本目录。其想法是让此应用程序移动,因为旧应用程序依靠静态目录在其应用程序包中包含的另一个应用程序Spore_origin.app中运行脚本。下面的代码:如何在AppleScript中修剪字符串?

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 

我想要做的是修剪这一关结束:

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

的突出显示的位需要修剪,但我不知道如何。帮帮我!!!!

回答

1

刚刚得到父文件夹。无需使用字符串操作

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

取决于路径的类型 - 如果你得到一个HFS路径,这也将工作

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

谢谢!我真的很陌生,我只想让这个该死的错误计划正常工作(他们在几年前停止了对它的支持)。 –

0
set myPath to POSIX path of (path to me) 
tell application "Terminal" 
    do script ("`dirname " & quoted form of myPath & "`/Spore_origin.app/Contents/MacOS/cider_noui") 
end tell