One of the great things about using the Unix command line in Mac OS X is that you are also using a Macintosh. So how do you access graphical Mac applications or AppleScripts from the command line? Apple provides a set of command-line tools to do exactly that.
To "double-click" a file from the command line:
You can specify which application to use with the -a switch (or option)for example,
open -a "BBEdit 6.5" found_files
would open the file called found_files using the BBEdit 6.5 application.
The open command is often used to open the current directory in the Finder:
To run an AppleScript from the command line:
If you are an experienced AppleScript programmer, read the Unix manual page for osascript by typing
You will also be interested in learning about the osacompile and osalang commands.
The Importance of Editing Text in Unix
Editing text from the command line is a crucial part of using Unix.
Unix system-configuration files, system-startup files, source code for software, and much documentation are all contained in text files, which you will have occasion to edit when using the command line.
While you can certainly use your favorite Aqua text editor or word processor to edit text in Mac OS X, you will need to be able to edit files directly from the command line if you do any serious command-line work. Also, if you want to be able to use other Unix systems besides Mac OS X, you will need to learn how to edit files using one of the command-line tools.
Chapter 6, "Editing and Printing Files," teaches you the basics of using the most common command-line text editor, the vi editor. In this chapter, you will use the simpler pico / nano editor, which is adequate for the example of creating a shell script but is not appropriate for more complex Unix work, such as editing system-startup files. (The nano editor is a compatible replacement for the more well-known pico editor, but nano has a less restrictive license and more features. On Mac OS X 10.4 the pico command actually runs nano .)