用applescript打开程序 [英] open programs with applescript

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

问题描述

2 部分问题:

我只是想从终端使用 applescript 运行程序,所以我尝试了:

I'm simply trying to run programs using applescript from the terminal, so I tried:

$ osascript tell application "iTunes" to activate

并得到错误:

osascript: tell: No such file or directory

提供程序的完整路径也不起作用.我错过了什么?问题的第二部分是我最终想用 applescript 做什么.我想用它来打开我使用 py2app 构建的应用程序.applescript 可以打开任何 mac 应用程序或只打开某些已经兼容的应用程序.

Giving the full path to the program did not work either. What am I missing? The second part of the question is what I eventually want to use applescript for. I would like to use it to open an application I built using py2app. Can applescript open any mac app or just certain ones that are already compatible.

谢谢

推荐答案

试试这个.请注意,您在编写命令时使用了-e".如果没有-e",您将提供一个运行applescript 的路径.还要注意字符串命令必须用引号引起来.

Try this. Notice you use "-e" when you are writing the command. Without "-e" you would give a path to an applescript to run. Also notice the string command must be in quotes.

osascript -e "tell application \"iTunes\" to activate"

如果你有一个多行的applescript,你可以在每一行之前使用-e",就像这样......

And if you have a multi-line applescript you use "-e" before each line like this...

osascript -e "tell application \"iTunes\"" -e "activate" -e "end tell"

如果你想打开一个应用程序,只需使用 unix "open" 命令...

If you want to open an application just use the unix "open" command...

open "/path/to/application"

如果您想使用 applescript 打开应用程序并且激活"命令不起作用(但它应该适用于几乎所有内容),然后告诉 Finder 打开它.请记住,applescript 使用冒号分隔的路径...

If you wanted to open an application using applescript and the "activate" command doesn't work (it should work for almost everything though) then tell the Finder to open it. Remember that applescript uses colon delimited paths...

osascript -e "tell application \"Finder\" to open file \"path:to:application\""

这篇关于用applescript打开程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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