How Documents Know Their Parents

Every operating system needs a mechanism to associate documents with the applications that created them. When you double-click a Microsoft Word document icon, for example, it’s clear that you want Microsoft Word to launch and open the document.

In Windows, every document bears a three-letter file name suffix. If you double-click something called memo.doc, it opens in Microsoft Word. If you double-click memo.wri, it opens in Microsoft Write, and so on.

Mac OS 9 uses a similar system, except that you never see the identifying codes. Instead, it relies on invisible, four-letter creator codes and type codes. Apple carefully monitors and tracks these four-letter codes, in conjunction with the various Mac software companies, so that no two codes are alike.

As a Macintosh/Unix hybrid, Mac OS X uses both creator codes (like Mac OS 9) and file name suffixes (like Windows).

It’s possible to live a long and happy life without knowing anything about these codes and suffixes. Indeed, the vast majority of Mac fans may never even encounter them. But if you’re prepared for a little bit of technical bushwhacking, you may discover that understanding creator/type codes and file name suffixes can be useful in troubleshooting, keeping your files private, and appreciating how Mac OS X works.

Type and Creator Codes

A Macintosh document’s four-letter creator code identifies the program that will open it.

If you’re feeling especially inquisitive, restart your Mac in Mac OS 9 and open Sherlock (

Type and Creator Codes

-F). (Or, if you’re running in Classic, choose

Type and Creator Codes

Sherlock.) Click Edit, and then drag the icon in question anywhere onto the Sherlock screen, as shown in Figure 4-6. As a little experimentation will soon show you, the creator code for a program and the documents it creates are identical—MSWD for Microsoft Word, FMP3 for FileMaker Pro, and so on. That’s the entire point: The creator code tells the Mac which program to open when you double-click a particular document.

Sherlock also reveals the second four-letter code in the DNA of most Macintosh icons: the type code. This code specifies the document’s file format. Photoshop, for example, can create graphics in a multitude of different formats: GIF, JPEG, TIFF, and so on. If you inspect your Photoshop documents, you’ll discover that they all share the same creator code, but have a wide variety of type codes.

Note

If the type code is supposed to identify the file format of a document, does a standard application have a type code?

It does: APPL.

When you double-click a document, Mac OS X checks to see if it has a creator code. If so, it then consults an invisible database of icons and codes. This database is the master index that lists the correspondence between creator codes and the applications that generate them. Together, the type and creator codes also specify which picture appears on a particular icon.

If the desktop file discovers a match—if, say, you double-clicked a document with creator code BOBO, which corresponds to the AppleWorks entry in your desktop database—then the corresponding program opens the document, which now appears on your screen.

Drag any icon from the desktop directly into Sherlock’s More Search Options screen to view the icon’s creator code, highlighted here at lower right. (Unfortunately, this feature doesn’t work in the Mac OS X version of Sherlock.) Capitalization and spaces count, so if you see a creator code that appears to have only three letters, then a space at the end is also part of the code.

Figure 4-6. Drag any icon from the desktop directly into Sherlock’s More Search Options screen to view the icon’s creator code, highlighted here at lower right. (Unfortunately, this feature doesn’t work in the Mac OS X version of Sherlock.) Capitalization and spaces count, so if you see a creator code that appears to have only three letters, then a space at the end is also part of the code.

File Name Extensions

In Mac OS 9, it was easy to spot a document whose type and creator codes had somehow become muddled. Its icon resembled a plain white piece of paper with a dog-eared corner. That was your cue that the Macintosh couldn’t find an entry for its type and creator codes in your desktop database, or that your desktop database had become corrupted.

In Mac OS X, however, plenty of documents don’t have type and creator codes. Documents created by Cocoa applications (Section 4.6), for example, generally don’t.

That’s because Mac OS X is a Unix operating system. In Unix, type and creator codes are unheard of. Instead, what determines which program opens when you double-click a document is its file name extension, just as in Windows. A file name extension is identifiable by a suffix following a period in the file’s name, as in Letter to Mom.doc.

In Mac OS X, the file name extension can be much longer. It can even identify the name of the program that will open when you double-click something. The file called Registration.setup, when double-clicked, launches the Mac OS X Setup application.

The bottom line is that Mac OS X offers two different mechanisms that associate documents with the programs that created them. Mac OS X looks for type and creator codes first. Where they’re absent, the file name suffixes kick in.

Hiding and Showing File Name Extensions

Mac OS X comes set to hide most file name extensions on the premise that they make the operating system look more technical and threatening. If you’d like to see them, however, choose FinderPreferences and turn on “Always show file name extensions.” Now examine a few of your documents; you’ll see that their names now display the previously hidden suffixes.

You can hide or show these suffixes on an icon-at-a-time basis, too (or a clump-at-a-time basis). Just highlight the icon or icons you want to affect and then choose FileGet Info. In the resulting Info window, proceed as shown in Figure 4-7.

Top: In the Info window, open the Name & Extension panel. Now you can see what Mac OS X really thinks your file is called. Turn “Hide extension” on or off if you’d like to see the file name suffix in the Finder. Bottom: If you try to add a suffix of your own, Mac OS X objects, in effect saying, “Hey—I’ve already got a file name extension for this, even if you can’t see it. Are you sure you know what you’re doing?”

Figure 4-7. Top: In the Info window, open the Name & Extension panel. Now you can see what Mac OS X really thinks your file is called. Turn “Hide extension” on or off if you’d like to see the file name suffix in the Finder. Bottom: If you try to add a suffix of your own, Mac OS X objects, in effect saying, “Hey—I’ve already got a file name extension for this, even if you can’t see it. Are you sure you know what you’re doing?”

Reassigning Documents to Programs

Unfortunately, type and creator codes aren’t of much use when you encounter a document created by a program that you don’t have. If I email you a MIDI file (a file-exchange format for music) that I exported from my Finale sheet music program, you won’t be able to open it simply by double-clicking, unless you, too, have Finale installed. Even if you have a different sheet music program on your hard drive, just double-clicking the MIDI file won’t, by itself, open it.

The file name extension system, meanwhile, has problems of its own. File name extensions are even less likely to pinpoint which parent program should open a particular document. Suppose you’ve downloaded a graphic called Sunset.JPG. Well, almost any program these days can open a JPEG graphic—AppleWorks, Word, Preview, Internet Explorer, and so on. How does Mac OS X know which of these programs to open when you double-click the file?

The answer is simple. You can reassign a document to a specific program (or all documents of its kind). Here’s the rundown:

Reassigning a certain document—just once

Double-clicking a graphics file generally opens it in Preview, the graphics viewer included with Mac OS X (see Section 9.1.16). Most of the time, that’s a perfectly good arrangement. But Preview can only display graphics—it can’t edit them. What if you decide to edit a graphics file? You’d want it to open, just this once, into a different program—GraphicConverter, for example.

To do so, you must access the Open With command. You can find it in two places:

  • Highlight the icon, and then choose FileOpen With.

  • Control-click the file’s icon (or right-click it, if your mouse has two buttons). From the contextual menu, choose Open With.

In any case, study the submenu for a moment (Figure 4-8, left). The program whose name says “(default)” indicates which program usually opens this kind of document. From this pop-up menu, choose the name of the program you’d rather open this particular file, right now, just this once.

Reassigning a certain document—permanently

After opening a TIFF file in, say, GraphicConverter for editing, you haven’t really made any changes in the fabric of your Mac universe. The next time you double-click that file, it will open once again in Preview.

If you wish this particular file would always open in GraphicConverter, the steps are slightly different. In fact there are three different ways:

  • Extend the one-shot reassignment method illustrated in In the Choose an Application dialog box, turn on “Always Open With” (shown at right in Figure 4-8).

  • Start out with one of the techniques described above (highlight the icon, and then choose FileOpen With, or Control-click the file’s icon and choose Open With)—but after you see the menu, press the Option key, too. Before your very eyes, the Open With command changes to say Always Open With.

  • Highlight the icon, and then choose FileGet Info. Open the “Open with” panel. Choose a new “parent” program’s name from the pop-up menu. You’ll see that the word “(default)” changes position, now tacking itself onto the name of the new program you’ve chosen.

    Note

    You can use the Get Info method to reassign the parenthood of a whole flock of selected icons at once. Once you’ve selected them, just choose FileGet Info, open the “Open with” panel, and choose a new program from the pop-up menu. The message at the top of the window—“22 items,” for example—reminds you that you’re changing the whole batch at once.

Left: The contextual menu offers a list of programs capable of opening an icon.. Right: If you choose Other, you’ll be prompted to choose a different program. Turn on “Always Open With” if you’ll always want this document to open in the new parent program; otherwise, this is a one-time reassignment.

Figure 4-8. Left: The contextual menu offers a list of programs capable of opening an icon.. Right: If you choose Other, you’ll be prompted to choose a different program. Turn on “Always Open With” if you’ll always want this document to open in the new parent program; otherwise, this is a one-time reassignment.

Reassigning all documents of this type

So much for reassigning one document (or group of documents) at a time. What if you’re writing, say, a book about Mac OS X, and you’ve been taking a lot of screenshots? Mac OS X saves each captured screen illustration as a graphics file in TIFF format. That’s all fine, except that every time you double-click one of these, it opens into Preview, where you can’t edit—you can only look.

Sure, you could reassign all of these files, one at a time, to a different program, but your grandchildren would be retired by the time you finish. In this case, you want to tell Mac OS X, “For heaven’s sake, make all TIFF files open in Photoshop from now on!”

To make it happen, use the Get Info method described previously. (You can’t do it using the FileOpen With command, nor by Control-clicking the icon.)

Start by highlighting any TIFF file. Choose FileGet Info. Open the “Open with” panel.

From its pop-up menu, choose the program you want to open this kind of document from now on. (If the one you prefer isn’t listed, use the Other option, which opens the Choose Application dialog box so that you can navigate to the one you want. Find, and double-click, the program.)

This time, however, follow up by clicking Change All beneath the pop-up menu. (This button is dimmed until you’ve actually selected a different program from the pop-up menu.) Mac OS X asks you to confirm by clicking Continue or pressing Enter.

From now on, double-clicking any similar kind of document opens it in the newly selected program.

Get Mac OS X: The Missing Manual, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.