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

查看:25
本文介绍了使用变量的应用程序的 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

它会回到我身边

"/Applications/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

但这只是告诉我错误

Finder 出错:无法将应用程序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)

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

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

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

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

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

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