• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 4. Changing Icons > Mac OS X Icon Files

4.1. Mac OS X Icon Files

As with past versions of Mac OS, each Mac OS X folder, file, and application has an intrinsic icon association. It's the Finder's job to use the file settings and its icon registry to select and display a particular icon. The Finder chooses icons based on a variety of factors, including the extension and creator (application) types. This section shows you how the Finder uses file extensions and creator codes to pick default icons.

4.1.1. Icons and extensions


For working through the examples in this section, you'll need the following application:

  • Terminal (/Applications/Utilities)

Open a Finder window and take a look through the kinds of files found on your computer. You'll probably see image files, documents, playlists, and programs. A quick peek is all it takes to distinguish one type of file from another. It doesn't matter if you're looking at the large images in the Finder's Icon view, or smaller pictures in the List or Column view. The images reveal themselves at a glance.

Each file on your computer presents the world with visual clues. Bold, vivid icons often reveal a file's type and its creator. Sometimes an icon offers a hint of a file's contents. Even when files are essentially the same thing, such as text, they appear with distinct looks. In Mac OS X, the icons for plaintext files do not look like rich-text files, and both differ from Microsoft Word files.

The first and simplest factor for assigning icons is found in a file's extension. Extensions such as .txt, .rtf, and .doc offer a basic distinction between file types. Extensions provide the most common way to differentiate file types for most computers. They're used in Windows and Unix as well as on the Mac. The Finder uses these extensions when choosing icon representations.

It takes just a few seconds to see the Finder's icon-association behavior in action. In these steps, you'll build Desktop items via the command line and allow the Finder to select icons to display based on file extensions:

  1. Launch the Terminal application (/Applications/Utilities) and size the window so you can see both the command line and the Desktop at the same time. If other application windows are open, Option--click on the Terminal's Dock icon to hide all of the other applications. That way, you'll have a clear view of the Terminal window and the Desktop beneath.

  2. Move to your Desktop directory:

    $ cd ~/Desktop

    You're about to create some new files. Creating them on the Desktop allows you to see each new item as it appears.

  3. The touch command allows you to create a new, empty file with a filename you specify. Use touch to create the files foo.txt, foo.rtf, and foo.doc, as follows:

    $touch foo.txt
    $touch foo.rtf
    $touch foo.doc

    The three new files appear on the Desktop, each using an automatic icon association based on its extension.

    Because of the way you create these files (via touch), there's no creator information stored in each file's metadata. All icon association occurs strictly by extension mapping.

  4. Now take a look at the icons for the files you just created; they'll look like those shown in Figure 4-1. (The icon for foo.doc may vary from the one shown if Microsoft Word isn't installed on your computer.)

    These three icons are associated with TextEdit (using plain text), TextEdit (using rich text), and Microsoft Word.

    Figure 4-1. File extensions help Finder determine the icon for displaying data files

    Use these directions to create other kinds of files by choosing different extensions. For example, try creating foo.swf (a Flash file), foo.mov (a QuickTime movie), or foo.key (a Keynote presentation file).

4.1.2. Icons and creator types

It would be all well and good if each file extension told you exactly which program created it and could edit or view it. In the real world, many file extensions are quite common, and many are associated with a wide array of applications. Take image files, for example. An application such as Photoshop can create standard Photoshop files (.psd), and can export image files in a variety of formats, including JPEG (.jpg), TIFF (.tif ), and PNG (.png). Extensions such as .jpg, .tiff, .aiff, .mp3, and .html may occur over and over again, and yet the Finder somehow figures out which application goes with which file and produces an icon to match.

The key lies in creator types. The Finder uses creator types to choose which icon to place on an otherwise indistinguishable file. Creator types are stored in each file's metadata, the information stored by Mac OS X about each file. Among other things, creator types help the Finder know which application to launch when you double-click a file. As Figure 4-2 shows, a Safari JPEG file icon appears distinct from a JPEG file created in Photoshop Elements. Each automatically opens in a different application. The six images shown here will open in Safari, Preview, Adobe Photoshop Elements (top row), QuickTime, Microsoft Internet Explorer, and iPhoto (bottom row). The iPhoto JPEG defaults to a blank document because the application does not define a specific icon association for JPEGs.

Figure 4-2. Icons indicate the application and file types associated with these otherwise identical JPEG images.

Creator types are defined by the application itself. Each application has a unique four-letter, case-sensitive code signature. This code is stored in the package bundle in two places. The first occurrence can be found in the PkgInfo file, and is composed of the fifth through eighth letters of that eightcharacter file. The second is found in the Info.plist file, as the value associated with the CFBundleSignature key. For example, iTune's code (rather sinisterly, in my opinion) is hook, Mail's is emal, QuickTime's is TVOD, and so forth. These codes are registered with Apple and are guaranteed (when registered properly) unique.

Apple reserves lowercase-only codes for its own use. Developer codes must use at least one uppercase letter.

The Finder uses creator codes to build its icon registry. It then uses the registry and a file's creator type to resolve overlapping extensions. When there's a conflict, it matches a file's creator type to its application and uses the icon assignments from that matching application bundle.

4.1.3. Testing associations


For working through the examples in this section, you'll need the following application:

  • Terminal (/Applications/Utilities)

In the following steps, you'll create a JPEG file and associate it with popular applications. This example allows you to see how you can assign files to specific applications.

  1. Launch the Terminal application and change directories to your Desktop:

    $cd Desktop 

  2. Use touch to create a new, empty file with a JPEG extension:

    $touch simple1.jpg

    A new file appears on your Desktop using the default icon for a JPEG file, which is probably Preview.

  3. Use the GetFileInfo command to view the current creator code:

    $GetFileInfo–c simple1.jpg

    GetFileInfo is installed as part of the Xcode Tools, and can be found in /Developer/Tools. If you issue the following command and you get an error saying that GetFileInfo could not be found, create a file named .bash_profile in your home directory and enter the following environment variable:

    export PATH=$PATH:/Developer/Tools

    Save the .bash_profile file and exit the Terminal session. When you open a new Terminal window, you should be able to use the GetFileInfo command without fail.

    GetFileInfo returns "", indicating that there's no intrinsic creator code. The -c flag tells GetFileInfo to return the creator code, but since the JPEG file was created with the touch command, there is no application of record associated with that file's creation. (Remember, when a creator code is assigned, the code is a four-character string.)

  4. The SetFile command (/Developer/Tools) can be used to add a creator code to a file. For example, we could use SetFile to turn the simple1.jpg file into a Safari document with the following command:

    $SetFile–c sfri simple1.jpg 

    The icon changes, displaying the Safari compass. (You may need to click on the Desktop or on the icon itself to encourage the Finder to update the icon.)

  5. Check the creator code again; GetFileInfo reads the updated file and returns its creator code:

    $GetFileInfo–c simple1.jpg

  6. Now change the creator code once more. Set the creator code to MSIE, the code used by Microsoft's Internet Explorer:

    $SetFile–c  MSIE simple1.jpg 

    Again, the file's icon changes, this time to Internet Explorer's gray document with a large white "e".

    Apple's Human Interface Guidelines (HIG) suggest that applications and their documents use bright, saturated colors for their icons. Gray, subdued, and desaturated icons are meant for utilities. (Compare the icons in /Applications with those in /Applications/Utilities.) Microsoft Explorer breaks this rule with its gray-colored document styling. Typical.

  7. Double-click the newly assigned icon. If Microsoft Internet Explorer is not already running, the program launches. The creator code tells the Finder which application to run, and Internet Explorer will attempt to load the JPEG file, but given that it's an empty file, IE will just display an empty browser window.

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint