Mac OS X Tiger for Unix Geeks

 < Day Day Up > 

The open shell command lets you open Finder windows and launch Aqua 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, enter the following command:

open .

Figure 1-8. Defining a bookmark to a new profile in iTerm

To open your Public folder (~/Public) in a Finder window, use the following:

open ~/Public

To open the /Applications folder in a Finder window, use the following:

open /Applications

To open an application, you need only its name. To open Xcode (/Developer/Applications), you would use the following:

open -a Xcode

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 use the -a 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, enter this 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 option directs the file to be opened in TextEdit; it cannot be used to open a file in another text editor, such as BBEdit (though BBEdit includes its own command-line application for this purpose). However, if you want to open a file using BBEdit, use the following:

open -a BBEdit filename

If you want to use TextEdit on a file that is owned by an administrator (or root), sudo open -e won't work. You'll need to specify the full path to the TextEdit executable, as in:

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

If you find yourself doing this often, you might want to create an alias for the path to TextEdit's executable file. For example, you could enter the following into your .bash_profile file:

alias sudotext="sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit "

Then the next time you want to open a text file that would otherwise require use of the sudo command, you could just use the following:

$ sudotext filename

When you enter that command, you'll be prompted for the admin password; once authenticated, the file you've specified is opened in TextEdit, just as you hoped it would.

Similar to the open command, the open-x11 command is used to open applications. However, it is for opening X11-based apps in Apple's X11 environment. You can learn more about X11 and the open-x11 command in Chapter 7.

     < Day Day Up > 

    Категории