I want to create command in terminal that would allow me to use
chrome index.html
and have the the given file open in Google Chrome.
How can I get this working?
I want to create command in terminal that would allow me to use
chrome index.html
and have the the given file open in Google Chrome.
How can I get this working?
You can use the open command with the -a flag to open a file or location in Chrome:
open -a "Google Chrome" index.html
This also works with URLs, i.e. open -a "Google Chrome" http://www.apple.com.
I found this way more beautiful:
~/.bash_profile file and add the following line
alias chrome="open -a 'Google Chrome'"source ~/.bash_profile or open a new window in Terminal.You can now open the file, file.html, by running: chrome file.html on the command line.
When using this from a script or some automation tool I prefer to alias to the complete binary so I have access to all the command line options, (like --version ...)
alias chrome="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
chrome --version
chrome -open index.html
Then if you want to have this alias permanently you can add it to your .bash_profile manually or using this little snippet:
echo "alias chrome=\"/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"\" >> ~/.bash_profile
From anywhere
start chrome path/file.html
just type the file name with extension if you are at that folder where file reside and your default browser should be chrome.
index.html
if chrome is not default Browser for that file
start chrome index.html
-bash: start: command not found when running start chrome, and -bash: index.html: command not found when entering index.html. Is there an addon which needs to be installed to make this work?
– nohillside
Apr 17 '21 at 13:00
open -a "Google Chrome" *.htmlopens all the matchedhtmlfiles as new tabs in the current Chrome's (active?) window – MichaelChirico Sep 22 '19 at 08:54