TypeIcons

HISTORY

I recently upgraded to "Snow Leopard" (SL) from a prior Tiger system where I had stored an old OS9 application that had both "data" and "rsrc" forks. Within the rsrc fork were several icon-families stored in ICNS# and icns#. ICNS# had 48x48 pixel icons, and icns# had 16x16 pixel icons and 32x32 pixel icons. Each of these families was associated with a four-character "Type" code, such as "CARD". The OS9 application had its own icon called APPL with the image associated with its APPL type. The "creator" code was another four-character code unique within the world of Apple applications.

The application produced files of different types within its icon-families. Each file received its corresponding icon whenever the "signature" of the file matched the "creator" and "type" of the old OS9 application.

All of this continued to work on Mac OS X 10.3.9 (Panther), and 10.4.11 (Tiger), and 10.5.8 (Leopard). A different application was producing the files, and this application had no icons associated with it. Basically, this new application was a C-program that ran in Terminal.app and used "SetFile -c [creator] -t [type] filename" to set the signature of the file. Since that signature matched the saved OS9 application, the files received the corresponding icons.

But when I upgraded to Snow Leopard, all these files lost their icons. SL no longer looked at "creator", only "type", and it didn't look at OS9 applications, so although the files still contained the old signature, they didn't show the corresponding icons.

THE FIRST STEPS

Fortunately, I had a bootable backup of my Leopard system on an external disk drive, so I connected it, via firewire, and booted from it. The procedure for that is to have the external drive mounted, then Restart the computer, and just as you hear the "bong!", press and hold the Option key. A panel of disk choices will appear showing all bootable volumes. This should include your internal hard drive, but it will also include any external volumes that have blessed operating systems. My Leopard backup still contained my icons, so I was able to click on my Leopard volume and press the "return" key to boot from that volume.

I then used Terminal.app to create files with the necessary icons. These are the steps, in Terminal, showing just the APPL icon:

    • cd Desktop
    • touch MyAPPL
    • SetFile -c [creator] -t APPL MyAPPL
    • touch APPL.png

NOTE: substitute the original application's [creator] code above.

Then, back in Finder, single-click on MyAPPL and do "Get Info", which is Cmd-i (Command eye). Cmd are the keys on either side of the space-bar. Doing Cmd-i causes an Info window to appear. At the top is the Icon left of the file's name. Single-click on the Icon in the Info window, and do Cmd-c (Copy). This copies that Icon to the clipboard. Do Cmd-w to close the window. Then single-click the APPL.png file, and do Cmd-i again. The Info window for that file now appears. Single-click on the Icon and do Cmd-v (Paste). The Icon should change to the APPL Icon. Lastly, do Cmd-w to close the Info window. You're done with one Icon.

Repeat this procedure for each of the other TYPE/icon pairs to get a set of files that have TYPE.png names and the TYPE icon as its image. All of these TYPE.png files have a custom-icon stored with them, which makes them transportable. You can leave these files on the Leopard Desktop, or copy them to your hard disk, or copy them to a plugged-in flash-drive. Be sure to eject a flash-drive when you're done copying.

You can now Restart again, but do NOT hold down the Option key. You'll be back to your hard disk system, which is Snow Leopard (in my case). Meanwhile, your TYPE.png files are either on a flash-drive, your hard disk, or your mounted external volumes. You can retrieve these TYPE.png files from wherever you placed them. Copy them to your Desktop.

THE NEXT STEP

I now created TYPE.icns files from the TYPE.png files. To do this, I installed Fasticns.app by downloading it. Do an Internet search for "Fasticns". I found this web-address: "www.macupdate.com/app/mac/22759/fasticns" which has a version that works on 10.4 or above. Click "Download Now". Once you have it installed (in Applications), as a temporary expedient, click-and-drag Fastincs in a Finder window showing Applications, to your Dock. You can drag it off the Dock when you're all done, if you desire.

Now, launch Fasticns from your Dock. A rotating blue cube will appear transparently floating on your Desktop.

Click-and-drag one of your TYPE.png files onto the cube, and its icon will now appear on the rotating faces of the cube. Single-click on the cube itself, and Fasticns will become the active application. Under its File-menu, "Save As..." allows you to save the image in different ways. I chose "icns (for OSX bundles)" with the same name as the TYPE, and stored them on my Desktop. I then repeated this paragraph for each of the other TYPE.png files.

Finally, single-click the blue cube, and Quit (Cmd-q) from Fasticns. I now had a set of TYPE.icns files, one for each TYPE, saved on my Desktop.

THE LAST STEPS -- BUILD AN APPLICATION

In order to make my icons reappear on my existing files that still have their original signature, but no corresponding icon, I had to construct a pseudo-app that SL would recognize so that the LaunchServices module would pick up the TYPE-codes and corresponding icons. Basically, this meant building something that looks like an application, and then renaming it so SL believes it's an application.

I created a tree of folders from Terminal:

    • cd ~/Desktop
    • mkdir mya
    • cd mya
    • mkdir Contents
    • cd Contents
    • mkdir Frameworks
    • mkdir MacOS
    • mkdir Resources
    • cd ~/Desktop

At this point you should place a do-nothing executable program into MacOS. The program's name can be anything, but I chose to use the same name as my original OS9 application. I created a C-program with that name as follows:

    • echo "int main() { return 0; }" >appname.c
    • gcc appname.c
    • mv a.out mya/Contents/MacOS/appname
    • rm appname.c

If you don't have "gcc", then you'll have to use a poor substitute:

    • echo "#!/bin/bash" >appname
    • echo "exit 0" >>appname
    • chmod 755 appname
    • mv appname mya/Contents/MacOS/appname

Replace "appname" by whatever name you want for your pseudo-app. You've now taken care of the application code.

Remember, your icns files should be on your Desktop. Move, or copy, all your TYPE.incs files to Resources:

mv *.icns mya/Contents/Resources/.

or

cp -p *.icns mya/Contents/Resources/.

What's left is to tie together your icons and TYPEs, and do so within the Contents of this pseudo-app. This requires you create an "Info.plist" within Contents. I have a file called "my.plist", all done in XML, which is required. You can download the attachment to this web page, which is the entire "my.plist" file. Save it on your Desktop.

You must edit my.plist using any standard text editor, like TextEdit. Find and replace "appname" by your actual application name, and replace [creator] by a unique four-character string, such as your initials in mixed upper/lower case padded digits. I used "Dg71". You also should replace "yourname" by your username. There may be a few other changes involving "Your", etc. You should change all the CFBundleTypeTypeOSTypes to be YOUR types, with a single TYPE.icns that applies. Notice both of these keys have array structures, but OSTypes are usually singular, although they can be multiple. Only singular types are shown. You can add more CFBundleTypeName descriptions within <dict>...</dict> pairs, just like to two shown in this model (CARD and FILE). Do NOT add Extensions.

If you have the Developer Tools installed, then you can view your my.plist file with the Property List Editor. From Finder, double-click my.plist on your Desktop, which should launch the Property List Editor.

Your pseudo-app is nearly complete. All you need to do now in Terminal is the following:

    • cd ~/Desktop
    • mv my.plist mya/Contents/Info.plist
    • mv mya /Applications/appname.app
    • touch /Applications/appname.app

This does three things. It moves my.plist into Contents as Info.plist, moves "mya" to the Applications folder with your actual "appname", and updates the modification date/time of your application. It's important to append the .app suffix. This will trigger the LaunchServices system to interrogate your new application, and record your TYPE/Icon pairs.

The application code can't be executed by double-clicking on the final application we just created. And it shouldn't be executed because it's only serving as a method to tell LaunchServices about your TYPE/Icon relationships. I'm still using C-programs in Terminal to make the files that were displayed in Finder with those old OS9 icons. Double-clicking those files will NOT launch this pseudo-app because of a "None" property included in the Info.plist.

Once this pseudo-app is scanned by LaunchServices, any file that has both your creator code AND one of your types, as shown by "GetFileInfo filename", will show your types' icon. For example, the file "MY.OBJ" with my creator code and TYPE=CARD will show the CARD icon.

            • ~/Desktop yourame$ GetFileInfo MY.OBJ
            • file: "/Users/yourname/Desktop/MY.OBJ"
            • type: "CARD"
            • creator: "Dg71"
            • attributes: avbstclinmedz
            • created: 01/01/2004 20:20:22
            • modified: 01/01/2004 20:20:22
Image of MY.OBJ