I decide to open a url in a new window with command:
$ open -na 'Google Chrome' 'https://www.etymonline.com/'
It opened a new window in blank.
google-chrome
I decide to open a url in a new window with command:
$ open -na 'Google Chrome' 'https://www.etymonline.com/'
It opened a new window in blank.
Best Answer
You need to use the
--args
option, e.g.:From the manual page for the open command:
For more Google Chrome command line switches that could be added to the
--args
option of theopen
command, check out the following URL.From: List of Chromium Command Line Switches
Another approach would be to use AppleScript from the command line, e.g:
For ease of use, you could wrap this in a function and place it in your
~/.bash_profile
or~/.profile
file, e.g:Then in Terminal, simply use the following, e.g.:
If you execute
openurl
without an argument, you get the following output:Note: The URL is shown wrapped in single quotes and this to ensure no expansion takes place when the URL is passed to the function if it has any shell special characters in it. The single quotes can be omitted for basic/simple URLs.
This same approach can be applied to the
open
command as well. That said, the reason I'd choose to wrap the AppleScript in a function is at some point theopen
command used in this manner with Google Chrome may break. This is because when Google Chrome is already open, it's opening a second instance, which is then passed to the first instance and the second instance terminated. This behavior may become problematic as Goggle Chrome is updated, where the AppleScript in a function will not, as it's only talking to the first instance of Google Chrome.