The open Command

The open shell command lets you open Finder windows and launch GUI applications. To open a directory in the Finder, use open, followed by the name of the directory. For example, to open a Finder window containing the current directory, type:

open .

To open your Public folder (~ /Public ):

open ~/Public

To open the /Applications directory:

open /Applications

To open an application, you need only its name. For example, you can open Xcode (/Developer/Applications) with this command:

open -a Xcode

Tip

You are not required to enter the path for the application, only its name—even if it is a Classic application. The only time you are required to enter the path is if you have two different versions of an application with similar names on your system.

You can also supply a filename argument with the -a option, which would launch the application and open the specified file with that application. You can use this option to open a file with something other than the application with which it’s associated. For example, to open an XML file in Xcode instead of the default XML editor, the Property List Editor, you could use the following command:

open -a Xcode data.xml

To open multiple files, you can use wildcards:

open *.c

To force a file to be opened with TextEdit, use -e:

open -e *.c

The -e switch will only open files in the TextEdit application; it cannot be used to open a file in another text editor, such as BBEdit (however, you can use the command-line bbedit application to open a file with BBEdit). If you want to use TextEdit on a file that is owned by an administrator (or root), open -e will not work. You’ll need to specify the full executable path, as in:

$ sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit filename

Get Mac OS X Panther for Unix Geeks, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.