Alastair’s Place

Software development, Cocoa, Objective-C, life. Stuff like that.

Getting Icons for Disks in Cocoa

This has been frustrating me all day. I wanted to get the icons for a set of disks attached to my Mac, so I could display them in a dialog box. How hard could it be, I thought?

Finding the name of the icon file was OK; you just use the IORegistry functions, from which you can obtain a CFDictionary containing the name of the file and the bundle’s identifier. And there’s the sticking point. You can’t (normally) get from an identifier to a bundle, unless the bundle is already loaded in your application…

After a lot of hunting around, I started searching through the IOKit headers and finally found KextManagerCreateURLForBundleIdentifier(), which lets you obtain an NSURL (or CFURL) directly from a bundle identifier. Just to see whether I had blindly wandered straight past the right bit of Apple’s documentation, I queried Google for this function, and I got (wait for it) Mac OS X 10.2 release notes (useless), and one (yes, one) reference in Apple’s documentation, buried in the “Displaying Localized Information About Drivers” section of Apple’s IOKit documentation.

The only thing wrong with Cocoa is the documentation.