Hack 11 Inspecting the Contents of an .app Package


If you were an OS 9 fiddler, tweaker, or deviant, there was one piece of software you simply had to have: ResEdit, Apple's venerable, unsupported, use-at-your-own risk utility. ResEdit is no longer applicable under OS X, but package editing is.

In earlier versions of the Mac OS, files could have data forks and resource forks. The data fork was the gooey inside, and the resource fork was the fluffy outside ? whether it be image thumbnails, saved editing data from applications like BBEdit, or application widgets, like window layouts, user interface images, and so forth. With Apple's ResEdit, you could easily access this resource fork and change the fluff ? it wasn't easily possible to change the coding of an application, but it was certainly mindless to change interface elements.

In OS X, with its grounding in the BSD operating system, resource forks are rarely used for applications, effectively making ResEdit useless. Instead, we've got packages or, less jargony, files that end in .app. You've got .app files spread all over your OS X system already ? you just may not know it. Take, for instance, Apple's popular Mail program. It sits innocently in your Applications folder, acting as if it were a single file. Instead, it's really called Mail.app; the .app is hidden from view (you can confirm its existence by examining the Get Info properties).

The magic of these .app files is that they're really a special kind of folder called a package; they contain a good portion of the same fluff available in an OS 9 application's resource fork. Even better, you don't need an extra utility like ResEdit to start fiddling; simply Control-click on a file you know is an .app and choose Show Package Contents, as shown in Figure 1-21.

Figure 1-21. Revealing package contents via Control-click context menu

Once inside the package Contents folder, you'll see a subfolder called Resources (see Figure 1-22). If you needed yet another hint that this is similar to ResEdit hacking, then this naming choice is it. In the case of Apple's Mail, we can see a decent number of image files, representative of various visual elements you see during normal use of Mail, as well as a few .plist, .toolbar, and .nib files.

Figure 1-22. Package resources

The .tiff and .icns files are obvious; modify them in your preferred graphic editor, restart Mail, and you'll see your changes. .plist files are the equivalent of preferences; there are usually frontends to these settings via the program itself (not always though ? in Mail's case, you can edit urlPrefixes.plist to add more clickable bits of text in mail messages, or Colors.plist to edit two more levels of quote coloring).

The .nib and .string files, located under English.lproj for English-speaking users, are where you can find some user-interface aspects of the program in question. You won't see these for every package you open (like iTunes), but in the case of Mail, you can go nuts editing warning messages, like this one in Prefs.strings (perhaps to the more ferocious "Ya Screwed Up, Idiot!"):

/* Title of panel shown when the user tries to enter an empty hostname for an account */
"INVALID_SMTP_HOST_TITLE" = "Invalid SMTP Hostname";

On the other hand, if you know your way around Apple's Interface Builder (available if you have the Apple Developer Tools [Hack #55] installed), you can open up one of the many .nib files and further tweak display elements.

As with the typical warnings when using ResEdit, be sure to make a backup before doing anything more than exploring (and exploring is when the best discoveries are made, like the ability to peel the annoying chrome [Hack #47] from a shiny iApp, add new boards and pieces to Chess, or change the default search engine in Internet Explorer).