Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terminal command to open Safari

Is there a way to open a new Safari tab with a given URL using a terminal command? I'm only interested for it to work on OSX at this point.

I want to use that command to open a new tab from a java application.

like image 513
Giannis Avatar asked Apr 19 '11 19:04

Giannis


2 Answers

If Safari is your default browser, you just use

open <url>

for example:

open http://www.google.com

You can also use this command to open any file with its registered application.

like image 195
Kai Sternad Avatar answered Oct 17 '22 23:10

Kai Sternad


There are several ways to do this. The simplest way would be to use /usr/bin/open:

/usr/bin/open http://stackoverflow.com/

will open the URL in the standard browser or

/usr/bin/open -a Safari http://stackoverflow.com/

will explicitly use Safari.

You can also use AppleScript via the javax.script API (JSR 223) but I do not know the syntax right now.

like image 32
Moritz Avatar answered Oct 17 '22 23:10

Moritz