Apple - Open URLs in New Chrome Window

You need to use the --args option, e.g.:

open -na 'Google Chrome' --args --new-window 'https://www.etymonline.com/'

From the manual page for the open command:

--args
All remaining arguments are passed to the opened application in the argv parameter to main(). These arguments are not opened or interpreted by the open tool.


For more Google Chrome command line switches that could be added to the --args option of the open command, check out the following URL.

From: List of Chromium Command Line Switches

There are lots of command lines which can be used with the Google Chrome browser. Some change behavior of features, others are for debugging or experimenting. This page lists the available switches including their conditions and descriptions.


Another approach would be to use AppleScript from the command line, e.g:

osascript -e 'tell application "Google Chrome" to set URL of active tab of (make new window) to "https://www.etymonline.com/"'

For ease of use, you could wrap this in a function and place it in your ~/.bash_profile or ~/.profile file, e.g:

openurl () 
{ 
    if [ -n "$1" ]; then
        osascript -e "tell application \"Google Chrome\" to set URL of active tab of (make new window) to  \"$1\""
    else
        printf "\n  Missing URL...\n\n    Syntax: openurl 'URL'\n\n    Example: openurl 'http://www.google.com'\n\n"
    fi
}

Then in Terminal, simply use the following, e.g.:

openurl 'https://www.etymonline.com/'

If you execute openurl without an argument, you get the following output:

$ openurl

  Missing URL...

    Syntax: openurl 'URL'

    Example: openurl 'http://www.google.com'

$

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 the open 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.