views:

182

answers:

1

In Objective-c/Cocoa, how do I get the icon that Finder uses for the desktop (it looks like the black/pink nebula desktop image with a menu bar and dock).

I tried this:

NSImage *icon = [[NSWorkspace sharedWorkspace] 
                 iconForFileType: NSFileTypeForHFSTypeCode(kDesktopIcon)];

But all I get is a blue folder with a ghosted desktop-looking box on it. Is there another constant that provides this icon, or another method altogether for getting the icon?

+1  A: 

The icon you're looking for is located at: /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarDesktopFolderIcon.icns

I wasn't able to find a constant for it, but you could load the image in with imageWithContentsOfFile:.

Yanik Magnan
Thank you!If anyone knows of a constant value for this (in case Apple changes its location) please post it here.
Alex B
Toolbar icons get their own constant names. That one is `kToolbarDesktopFolderIcon`.
Peter Hosey
BTW, if you want to find out about more of these icons, IconsCore.h is really good reading. You can try out the icons using my IconGrabber application: http://boredzo.org/icongrabber (requires Rosetta)
Peter Hosey
This is akin to using unpublished methods. You cannot rely on this path, it could change between releases (and is pretty likely to, actually). As the +[NSImage imageNamed] release notes say, "If there is no image available for the situation you're interested in, please file a bug and use your own custom art in the meantime.". Peter, for 10.6 we (the Cocoa group) went through Icons.h with the human interface group, and made NSImage names for everything judged still recommended for general use. File bugs for anything else.
Ken
@Peter Hosey: I just tried kToolbarDesktopFolderIcon and it's undeclared for me. Maybe it's Snow Leopard-only?
Yanik Magnan
kToolbarDesktopFolderIcon worked for me(!) and I have 10.6 so it must be new in Snow Leopard. I wonder why the Cocoa group removed it from Icons.h and put it in IconsCore.h?
Alex B