3

如果我有一个这样的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”转换为类型常量。”

任何想法我怎么能做到这一点?

4

1 回答 1

4

答案(或至少一个答案)是:

set theApp to "MyApp"
set pathToTarget to POSIX path of (path to application theApp)

由于应用程序的路径是标准添加的一部分,因此不需要 Finder。

感谢 MacScripter 上的 Stephan K 让我明白这一点。

于 2009-07-31T19:58:01.587 回答