Mac OS XSpecific Utilities

Mac OS XSpecific Utilities

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.

open"Double-click" files and directories from the command line

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 .

osascriptRun AppleScript from the command line

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

Need Help?

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:

  • osascript filename

    This executes the AppleScript contained in the file represented by filename .

    For example, if you have a script called playsong that contains

     tell application "iTunes" open file  "MyDisk:Users:vanilla:Desktop:  slow_ride.mp3 end tell 

    then the command line

    osascript playsong

    would run the AppleScript, launching iTunes and opening the slow_ride.mp3 file ( Figure 4.1 ).

    Figure 4.1. iTunes running a file opened from the command line.


  • 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.

Learning AppleScript

AppleScript is a complete language for controlling your Macintosh using scripts. Here are some resources for learning more about AppleScript:

  • The main Apple Computer Web site for AppleScript is

  • Go to the AppleScript Documentation page (

pbcopy and pbpasteCommand-line interface to the pasteboard ("clipboard")

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:

  • pbcopy < filename

    The contents of the file are now on the clipboard. If the file contents are not plain text, EPS, or RTF, then nothing is placed on the clipboard. If you now choose "paste" in an Aqua application, the contents of the file will appear.

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.)

Unix for Mac OS X 10. 4 Tiger. Visual QuickPro Guide
Unix for Mac OS X 10.4 Tiger: Visual QuickPro Guide (2nd Edition)
ISBN: 0321246683
EAN: 2147483647
Year: 2004
Pages: 161
Authors: Matisse Enzer

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: