Terminal command to open Safari
25,751
Solution 1
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.
Solution 2
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.
Comments
-
Giannis almost 3 years
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.
-
Giannis about 13 yearsCould you tell me the difference between /user/bin/ open and the way @bunting suggested ?
-
Moritz about 13 years
/usr/bin/open
is just the full path. You will need the full path if you use e.g.ProcessBuilder
to execute it. -
austin almost 10 yearsmixing your solution with that of Moritz, if Safari is not your default browser use
open -a Safari <url>
-
Giannis over 4 yearsThats exactly the same as existing answer? :)