Some utilities on your system are specific to Mac OS X/Darwin; the appendix describes almost all these commands. Here we will describe a few of them, the ones a beginner is most likely to use, and those that do not fit easily into one of the other categories in this chapter (see also the textutil and mdfind commands later in this chapter).
Throughout this book we mark commands that are specific to Darwin with the Darwin logo:
Some of these commands deal with the differences between traditional Macintosh files and Unix files, while others provide connections between the Darwin layer and the Aqua layer. The developer tools in /Developer/Tools are mostly examples of the former, while the open and osascript commands are examples of the latter. (If you haven't installed the Developer Tools, you should do so now; they installed as part of the XCode tools on the Mac OS X installation DVD (or CDs if you have traded in your DVD for CDs).
The following are the most important of the Mac OS Xspecific commands you are likely to use in day-to-day work.
The open command in Unix works the same way as a double-click on the Mac: It lets you open one or more files from the command line. And with the -a option you can achieve an effect similar to drag and drop by specifying an application to use when opening a file. See man open for the Unix manual entry and Chapter 2 of this book for an example of using open .
AppleScript is the Mac-specific scripting language that allows you to control Mac applications from scripts (see the "Learning AppleScript" sidebar). In Mac OS X you can run AppleScripts from the command line using the osascript command.
To get a list of the Open Scripting Architecture (OSA) languages installed on your system, use osalang . For documentation on AppleScript itself, see www.apple.com/applescript.
In Chapter 3, "Getting Help and Using the Unix Manual," we showed you how to use the man command to search for commands by keyword. Some of the commands in this chapter are covered in detail elsewhere in this book. In each case, we'll refer you to the appropriate chapter rather than repeat the information. In any event, it is a good idea to read the Unix manual entry for each of the commands described here. Even if you don't understand all of what you read, you will get a good sense of what is possible and will see references to other related commands (in the "See also" section of each man page). For more on using the Unix manual, refer back to Chapter 3.
To run an AppleScript from the command line:
tell application "iTunes" open file "MyDisk:Users:vanilla:Desktop: slow_ride.mp3 end tell
Notice that AppleScript expects files to be described using colons to separate the names of folders. This is quite different from Unix commands, which expect you to use the slash character (/), prevalent throughout this book.
AppleScript is a complete language for controlling your Macintosh using scripts. Here are some resources for learning more about AppleScript:
The pbcopy and pbpaste commands copy and paste data between STDIN / STDOUT and the Mac OS X clipboard. (See "About Standard Input and Output" in Chapter 2.)
This means you can copy something onto the clipboard from the command line and then paste it in an Aqua application, and you can copy something in an Aqua application and paste it into a command line. Currently pbcopy and pbpaste handle only plain text, Encapsulated PostScript (EPS), and rich text format (RTF).
To copy the contents of a file onto the clipboard:
To paste from the clipboard into a command line:
Copy something into the clipboard in an Aqua application.
pbpaste > filename
The file now contains whatever you copied in step 1. (Only plain-text, RTF, and EPS content will be pasted.)