2017-07-18 160 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