AppleScript的应用程序的路径使用可变 [英] Applescript path to application using variable

查看:94
本文介绍了AppleScript的应用程序的路径使用可变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个AppleScript代码片段,如本

If I have an applescript snippet such as this

tell application "Finder"
set thePath to (POSIX path of (path to application "MyApp"))
end tell

它会退还给我。

/应用/ MyApp.app

"/Applications/MyApp.app"

现在,我似乎无法弄清楚是如何通过一个变量而不是文字而是指定MyApp的。

Now, what I can't seem to figure out is how to instead specify "MyApp" via a variable rather than the literal.

我的AppleScript一些XML值读取,其中之一是我在有趣的应用程序的名字我已经试过这样:

My applescript reads in some XML values, one of them being the name of the application I'm interesting in. I've tried this:

tell application "Finder"
set thePath to (POSIX path of (path to application someVariable))
end tell

但这只是告诉我的错误

but this simply tells me the error

查找器得到了一个错误:无法提出申请。入式恒的MyApp

"Finder got an error: Can't make application "MyApp" into type constant."

任何想法我怎么可以这样?

Any ideas how I can do this?

推荐答案

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

The answer (or at least one answer) is:

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

由于应用程序的路径的标准添加的一部分,不需要搜索引擎。

Since path to application is a part of Standard Additions, the Finder is not needed.

感谢斯蒂芬·K于MacScripter直设置我在此。

Thanks to Stephan K on MacScripter for setting me straight on this.

这篇关于AppleScript的应用程序的路径使用可变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆