Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using Mac OSX "open" command to open URL with -n flag

I'm having trouble getting /usr/bin/open to open a browser to a specific URL when using the -n flag.

For example, this will work:

open -a "Google Chrome" "https://stackoverflow.com"

...successfully opening the desired page. However, if my browser is already open, it will open it in an existing window as a tab. The man page for open says this should be remedied with the -n flag, but:

open -n -a "Google Chrome" "https://stackoverflow.com"

...opens a new instance (window) of my browser to the homepage without navigating to the desired URL.

I've also tried moving around the -n flag in the command and messing with other flags (such as -F).

environment: macOS Sierra 10.12.6

UPDATE: Here are some other solutions I've tried...

I've tried adding --args before the URL. This makes it behave like the first command above, essentially ignoring the -n flag....

open -n -a "Google Chrome" --args "https://stackoverflow.com"

...will open the desired URL, but again in a tab and not a new window.

I've tried making '--new-window' an option for --args:

open -a "Google Chrome" --args '--new-window' "https://stackoverflow.com"

...this behaves the same way as the -n flag, opening a new window but not passing it a URL.

I've also tried putting the URL before the --args:

open -n -a "Google Chrome" "https://stackoverflow.com" --args '--new-window'

...this behaves as if I did not put the --args flag, opening the URL in another tab.

like image 245
jebrii Avatar asked Dec 05 '22 13:12

jebrii


1 Answers

This works on my OSX El Capitan. The --new-window is a chrome argument, a list of which can be viewed here

open -n -a "Google Chrome" --args "--new-window" "https://stackoverflow.com"
like image 136
Vasan Avatar answered Dec 27 '22 20:12

Vasan