using Mac OSX “open” command to open URL with -n flag

北战南征 提交于 2019-12-26 04:21:29

问题


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.


回答1:


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"



回答2:


After much trial and error, I've found that this is indeed possible and that it can be done in two ways:

...passing the -n flag to open and the --new-window arg to Google Chrome:

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

...ordering the parameters correctly such that the --args flag comes after the URL param (note that the -n flag passed to open will break this):

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

These open a new window with the specified URL.



来源:https://stackoverflow.com/questions/47042814/using-mac-osx-open-command-to-open-url-with-n-flag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!