1

In order to run Chrome from the Terminal application, I have to do

open -a "Google Chrome" index.html

rather than just something like "chrome index.html".

The same also seems to be true for Firefox.

It's not because I can't open any GUI applications from the command line. For example, I can do mate . to open TextMate.

What's the rationale for web browsers not having a command like "chrome index.html"?

  • Did you see my updated answer? – user3439894 Mar 30 '15 at 1:09
  • NB mate is not a GUI application. It is a commandeline executable that happens to call a GUI app. ie mate is the exception – Mark Aug 7 at 17:31
2

To open a application from the terminal it has to be in one of the paths of your $PATH environnement variable.

By default /Application/ where Chrome is located is not in your path. Therefore you can't launch an application without giving the full path to your app.

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome http://google.com

Will work.

  • 1
    It will work however you cannot then close Terminal without also closing Google Chrome. In this case using open -a Google Chrome is the proper way as it's process is not terminated when closing the Terminal. – user3439894 Mar 29 '15 at 23:23
  • @user3439894, Isn't .app needed? – Pacerier Dec 15 '17 at 15:46
  • @Pacerier, First let me start by saying the command I posted in the comment should have been open -a Google\ Chrome or open -a 'Google Chrome' and no, .app is not needed. Read the manual page for the open command. You'll see examples for an application where .app is used and not used for an application. So either works, and I'm not going to type 4 extra characters when they are not needed. :) – user3439894 Dec 15 '17 at 16:26
4

It's probably safe to say that most Mac users do not open GUI apps via the CLI, which is why most GUI apps do not include the CLI support like TextMate does. In other words, TextMate actually includes a binary executable named mate which is installed in $PATH, which is why one does not need to preface it with the open command like opening a GUI app which does not include that type of CLI support.

If you want to emulate that behavior then create a script named chrome placed in the $PATH, typically /usr/local/bin/ for something such as this.

Example:

#!/bin/bash

if [ -n "$1" ]; then
    open -a "Google Chrome" "$1"
else
    open -a "Google Chrome"
fi

Save the above code in a plain text file named chrome and make it executable by:

chmod +x chrome

Then you can start Google Chrome via CLI by chrome or chrome URL where URL is properly formatted if not just a filename in the $PWD.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .