| Main |

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.

Trackbacks

TrackBack URL for this entry:
http://alastairs-place.net/movabletype/mt-tb.cgi/3.

Comments

Post a comment

If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thank-you for your patience.

(Your e-mail address will not be displayed or included in any pages served on this site; nor will you get any spam as a result.)

A live preview of your comment will be displayed below. It should refresh automatically when you stop typing, but if not then the “Preview” button above will update it.

Live Comment Preview