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 'It focuses Chrome but does not open the URL.
110 Answers
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)
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" 'OS X version: 10.6.8
1If you set Google Chrome as your default browser
open will just do the trick.
OS X version: 10.8.4
3You 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/chromethen run the following to open a file in chrome from the terminal
chrome /path/to/some/file
I've an alias for google
function google() { open /Applications/Google\ " $1"; } 2 Get rid of the --args. open already knows how to handle URLs.
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.
Open a URL in the default browser (could be Chrome):
openOpen a URL in Chrome always (using the app name):
open -a "Google Chrome"Open a URL in Chrome always (using the app path alternative syntax):
open -a /Applications/Google\Open a URL in Chrome always (using the bundle identifier alternative syntax):
open -b com.google.chromeOpen 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" --args --incognitoHowever, you can do it by passing the Chrome command line switches directly to the Chrome binary:
/Applications/Google\ Chrome --incognito
this is my method.
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="" fi /usr/bin/open -a "/Applications/Google Chrome.app" "$site"; }Load ~/.bash_profile:
source ~/.bash_profileLunch chrome and open a site:
chromeOpen a local site:
chrome LOCAL_SITE_PATH
In macos Sierra 10.12.6 .If chrome is your default browser. You can do this byopen index.html
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)