The MacOS X open(1) Command

MacOS X provides a commnad line tool to open applications and files. MacOS X applications are actually collections of files residing within one directory with a name ending in .app. I usually use open at the command line to start most applications, leaving the Dock clear of applications not running:

[email protected]:~$ open /Applications/Safari.app

is enough to start Safari and if the browser is already running, it will open a new window.

The open command also works on individual files and will open the file in its associated application. For instance, running open on a PDF will open the file in Preview. And running open on a normal directory (as opposed to an application package) will open the directory in Finder.

The open command provides a number of useful options. The option t treats the file, regardless of type, as a text file and opens it in the default text editor. A related option, e simplifies the process and opens the file in TextEdit, the native text editor provided with MacOS X. Also related is f, which reads from the standard input and passes the input to the default text editor.

It is also possible to override the default application with other types of files using the option a. But it is important to remember the full path to the application must be given:

open -a /Applications/Adobe Reader 9/Adobe Reader.app/ foo.pdf

This form is quite cumbersome, but it may be appropriate in some circumstances. One last option worth mentioning is R which find the references file in Finder, instead of opening the file itself. Of course, open supports other options as well and reveiwing the man page is advised.

Finally, the open supports URLs:

open http://www.jameshoward.us

will open my website directly in the default browser.