1. The MacOS X open(1) Command

    MacOS X provides a commnad line tool to open applications and files. MacOS X applications are actually collections of files residing within one directory with a name ending in .app. I usually use open at the command line to start most applications, leaving the Dock clear of applications not running:

    howardjp@thermopylae:~$ open /Applications/Safari.app

    is enough to start Safari and if the browser is already running, it will open a new window.

    The open command also works on individual files and will open the file in its associated application. For instance, running open on a PDF will open the file in Preview. And running open on a normal directory (as opposed to an application package) will open the directory in Finder.

    The open command provides a number of useful options. The option t treats the file, regardless of type, as a text file and opens it in the default text editor. A related option, e simplifies the process and opens the file in TextEdit, the native text editor provided with MacOS X. Also related is f, which reads from the standard input and passes the input to the default text editor.

    It is also possible to override the default application with other types of files using the option a. But it is important to remember the full path to the application must be given:

    open -a /Applications/Adobe\ Reader\ 9/Adobe\ Reader.app/ foo.pdf

    This form is quite cumbersome, but it may be appropriate in some circumstances. One last option worth mentioning is R which find the references file in Finder, instead of opening the file itself. Of course, open supports other options as well and reveiwing the man page is advised.

    Finally, the open supports URLs:

    open http://www.jameshoward.us

    will open my website directly in the default browser.

  2. pbcopy and pbpaste

    The Unix command line has historically interacted poorly with the numerous graphical interfaces that have been stacked upon it. One key area lacking support is the clipboard. MacOS X brings two utilities to close that gap, pbcopy and pbpaste. These commands together provide complete access to the MacOS X clipboard (which Apple calls the pasteboard, explaining the names of these two commands).

    The first of the two, pbcopy, takes its input from the standard input and adds it to the system clipboard. The command only accepts one option, -pboard, which accepts one of four suboptions, “general”, “ruler”, “find”, and “font”, all of which are different system clipboards available on MacOS X. The general pasteboard is the main system clipboard and the others are for special use.

    The pbpaste pulls data from the clipboard and prints it to the standard output. Like pbcopy, pbpaste accepts the option -pboard to determine which pastebaord to acquire data from. The pbpaste command adds a second option, -Prefer which takes three possible options “txt”, “rtf”, and “ps”. These options direct \cmd{pbpaste} looks for a certain type of formated information on the pbasteboard. The “txt” flag suggests standard text data. The “rtf” and “ps” suggest Rich Text Format and PostScript, respectively. Despite this option, it is not possible to direct the exact output pbpaste prints. This option only tells pbpaste what type of information to return first.

    These two commands offer the MacOS X command line warrior a simple and fairly complete set of tools for working with and manipulating the MacOS X pasteboards.