简体   繁体   English

如何在由Shell脚本启动的程序中打开URL?

[英]How to open a URL in a program started by a shell script?

In order to extract data from a website, I would like to open a program that does just this and open a URL inside (!) the running application. 为了从网站提取数据,我想打开一个执行此操作的程序,然后在正在运行的应用程序内(!)打开URL。 I would like to execute this as a shell script. 我想将其作为shell脚本执行。

echo "Launching Program"

#if ["$1" -eq "0"]; then
# Application exited successfully. Restarting.

/Users/Path/to/app/Contents/MacOS/app
open http://www.example.com

#else
# An error occured. Do nothing and exit.
# exit
#fi

This is what I got so far, but this starts the application and opens the URL in a separate browser window. 到目前为止,这就是我所得到的,但这将启动应用程序并在单独的浏览器窗口中打开URL。 I would like to open the URL inside of the application and also perform other actions with the retrieved data later on. 我想在应用程序内部打开URL,并且稍后还要对检索到的数据执行其他操作。 What would be the best way to do that? 最好的方法是什么? How can I "interact" and perform actions inside a running application from the command line on Mac OS? 如何在Mac OS上的命令行中“交互”并在正在运行的应用程序中执行操作?

Any hints would be appreciated. 任何提示将不胜感激。

You can tell open to use something other than the default application for the file to be opened: 您可以告诉open使用默认应用程序以外的其他方式来打开文件:

open -a /Users/Path/to/app http://www.example.com

Interacting with the program requires that the application be scriptable (generally with AppleScript, but possibly some other scripting language), or more painfully (if the application itself isn't scriptable) using AppleScript to simulate using the GUI of the application. 与该程序进行交互要求该应用程序是可编写脚本的(通常使用AppleScript,但也可能使用某些其他脚本语言),或更痛苦的是(如果该应用程序本身不可编写脚本)使用AppleScript来模拟使用该应用程序的GUI。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM