8

I'm having trouble with opening Safari from terminal. Command I tried is

/Applications/Safari/Contents/MacOS/Safari http://www.example.com

Safari opens and tries to navigate to the url:

file:///Current/Terminal/Path/Here/http:/www.example.com

I know, I could do it using open:

open -a safari http://www.example.com

But I can't. The bigger picture is quite complicated: I'm actually trying to run the browser from command-line .NET application (which is running using mono). I use System.Process .NET class to run the command and I have to be able to control the process (get process Id, check if it's active, kill it if necessary, etc.). Using open command does not return correct process Id (I tried using open with -W switch - does not help either).

6

One solution would doing this in 2 times

  • Open safari
  • Using AppleScript to open the url tell application "Safari" to open location "http://www.google.com"

Here is a oneliner :

/Applications/Safari.app/Contents/MacOS/Safari & sleep 1 && osascript -e 'tell application "Safari" to open location "http://www.google.com"'

NB: you need to wait before running the AppleScript because Safari is not started yet. The sleep 1might not work in every case since it will really depend on how much time Safari will need to start.

  • It get's a little more tricky because I'm trying to fire it from Process .NET class, but I was able to work problems around using your solution, and that's why I'm setting it as accepted. Thanks! – MarcinJuraszek Dec 17 '13 at 21:05

protected by Community Sep 11 '15 at 19:03

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.