102

How can I open a URL in Google Chrome from the terminal in OS X?

This is what I'm trying:

/usr/bin/open -a "/Applications/Google Chrome.app" --args 'http://google.com/'

It focuses Chrome but does not open the URL.

1
  • why do you reference the open programm by it's path? It's aliased by default! May 11, 2013 at 4:31

10 Answers 10

59

If you remove the --args it seems to work fine, since --args can only affect things on first launch (it changes what main gets called with)

1
  • weird. seems like i used to have to use them. thanks.
    – cwd
    Oct 18, 2011 at 4:48
66

Actually for me, the command is not working with the "--args" being present so the command working for me is

/usr/bin/open -a "/Applications/Google Chrome.app" 'http://google.com/'

OS X version: 10.6.8

1
  • can you pipe string in place google Oct 14, 2020 at 2:03
50

If you set Google Chrome as your default browser

open http://google.com/

will just do the trick.

OS X version: 10.8.4

3
  • OS X 10.10 Yosemite as well.
    – leymannx
    Jun 17, 2015 at 9:28
  • This only works if google chrome is your default browser. If you're using safari, firefox or another option but want to open the URL with chrome you'll need one of the other options.
    – tgf
    Mar 17, 2016 at 2:32
  • 1
    good answer, now how do I do this in a new Chrome window?
    – chharvey
    May 13, 2016 at 2:31
11

You can use

open -a "Google Chrome" index.html

or, to put it in a shell script (e.g. ~/bin/chrome)

  • edit the file ~/bin/chrome, and put the following in it

    open -a "Google Chrome" "$*"

  • make the file executable by running the following in a terminal

    chmod 700 ~/bin/chrome

  • then run the following to open a file in chrome from the terminal

    chrome /path/to/some/file

Pulled from here

1
  • 2
    function chrome(){ open -a "Google Chrome" "$*" } Jul 1, 2015 at 7:40
7

I've an alias for google

function google() { open /Applications/Google\ Chrome.app/ "http://www.google.com/search?q= $1"; }
2
  • that's a great idea :) May 11, 2013 at 4:30
  • 1
    for zsh: chrome() { open -a "Google Chrome" "http://www.google.com/search?q=$1"; }
    – nbari
    Jun 17, 2015 at 10:02
6

There are several helpful answers here but none that contain the complete info for opening a URL in Chrome in both cases whether it is or is not the default browser.

  1. Open a URL in the default browser (could be Chrome):

    open http://www.example.com
    
  2. Open a URL in Chrome always (using the app name):

    open -a "Google Chrome" http://www.example.com
    
  3. Open a URL in Chrome always (using the app path alternative syntax):

    open -a /Applications/Google\ Chrome.app/ http://example.com
    
  4. Open a URL in Chrome always (using the bundle identifier alternative syntax):

    open -b com.google.chrome http://www.example.com
    
  5. Open a URL in Chrome in an incognito window always:

    From man open, it would seem that you should be able to do it like this (but alas it does not seem to get the incognito option to Chrome):

    open -a "Google Chrome" http://example.com/ --args --incognito
    

    However, you can do it by passing the Chrome command line switches directly to the Chrome binary:

    /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --incognito http://example.com
    
4
  • This answer, your 5th point, but without --incognito - is what I came looking for, and could not find elsewhere. I was wondering how to bypass open (which does not support chrome-extension://) - so I could do like so, /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome 'chrome-extension://<gobbledygook>/views/default.html#/' ... where I've copied the URL from an extension. I'm using this to open Jironimo (for JIRA) and OneTab, when I cd into work-project directory for first time each day.
    – floer32
    May 6, 2019 at 23:44
  • I'm trying to achieve something similar to @driftcatcher but his method won't work for me (macOS 11.0.1, Chrome 90.0.4430.72) when trying to open a chrome:// scheme, it just opens a new window with a blank tab. Some security measure maybe? If anyone knows a workaround, I'd appreciate the ping.
    – lima
    Apr 16, 2021 at 17:19
  • 1
    @lima It does seem like the browser prevents loading the chrome:// scheme programmatically for security purposes. twitter.com/anatudor/status/1099590311540609024 Apr 16, 2021 at 18:58
  • @TaylorEdmiston Thanks for looking into it. I suspect something can be done using osascript, but I ended up just quoting the URL and calling it a day.
    – lima
    Apr 16, 2021 at 22:53
4

Get rid of the --args. open already knows how to handle URLs.

2

this is my method.

  1. Update ~/.bash_profile and add the chrome function below:

    function chrome(){ 
        local site=""
        if [[ -f "$(pwd)/$1" ]]; then
            site="$(pwd)/$1"
        elif [[ "$1" =~ "^http" ]]; then
            site="$1"
        else
            site="http://$1"
        fi  
        /usr/bin/open -a "/Applications/Google Chrome.app" "$site"; 
    }
    
  2. Load ~/.bash_profile:
    source ~/.bash_profile

  3. Lunch chrome and open a site:
    chrome www.google.com

  4. Open a local site:
    chrome LOCAL_SITE_PATH

1

In macos Sierra 10.12.6 .If chrome is your default browser. You can do this by
open index.html

0

Using chrome-cli:

chrome-cli open <url>  (Open url in new tab)
chrome-cli open <url> -n  (Open url in new window)
chrome-cli open <url> -i  (Open url in new incognito window)
chrome-cli open <url> -t <id>  (Open url in specific tab)
chrome-cli open <url> -w <id>  (Open url in new tab in specific window)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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