DWA
DWA

Reputation: 530

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. I would like to execute this as a shell script.

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. I would like to open the URL inside of the application and also perform other actions with the retrieved data later on. 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?

Any hints would be appreciated.

Upvotes: 0

Views: 1003

Answers (1)

chepner
chepner

Reputation: 530922

You can tell open to use something other than the default application for the file to be opened:

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.

Upvotes: 2

Related Questions