如果我有像这样的AppleScript代码段
tell application "Finder"
set thePath to (POSIX path of (path to application "MyApp"))
end tell
它会回到我身边
“/应用/ MyApp.app”
现在,我似乎无法弄清楚如何通过变量而不是文字来指定“MyApp”。
我的AppleScript读入了一些XML值,其中一个是我感兴趣的应用程序的名称。我试过这个:
tell application "Finder"
set thePath to (POSIX path of (path to application someVariable))
end tell
但这只是告诉我错误
“Finder遇到错误:无法将应用程序”MyApp“变为类型常量。”
我有什么想法可以做到这一点吗?
答案 0 :(得分:4)
答案(或至少一个答案)是:
set theApp to "MyApp"
set pathToTarget to POSIX path of (path to application theApp)
由于应用程序路径是标准添加的一部分,因此不需要Finder。
感谢MacScripter上的Stephan K让我直截了当。