如果我有这样的 applescript 片段
tell application "Finder"
set thePath to (POSIX path of (path to application "MyApp"))
end tell
它会回到我身边
“/Applications/MyApp.app”
现在,我似乎无法弄清楚的是如何通过变量而不是文字来指定“MyApp”。
我的 applescript 读取了一些 XML 值,其中之一是我感兴趣的应用程序的名称。我试过这个:
tell application "Finder"
set thePath to (POSIX path of (path to application someVariable))
end tell
但这只是告诉我错误
“Finder 出现错误:无法将应用程序“MyApp”转换为常量类型。”
有什么想法可以做到这一点吗?
最佳答案
答案(或至少一个答案)是:
set theApp to "MyApp"
set pathToTarget to POSIX path of (path to application theApp)
由于应用程序路径是标准添加的一部分,因此不需要 Finder。
感谢 MacScripter 上的 Stephan K 让我明白了这一点。
关于使用变量的应用程序的 Applescript 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1214475/