Why can't I easily open web browsers from the terminal application?

Solution 1:

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.

Solution 2:

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.