0

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?

Alex B
  • 1,438
  • 13
  • 17

1 Answers1

0

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
  • 597
  • 3
  • 8
  • Thank you! If anyone knows of a constant value for this (in case Apple changes its location) please post it here. – Alex B Sep 05 '09 at 16:57
  • 1
    Toolbar icons get their own constant names. That one is `kToolbarDesktopFolderIcon`. – Peter Hosey Sep 05 '09 at 18:39
  • 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 Sep 05 '09 at 18:41
  • 1
    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 Sep 05 '09 at 19:21
  • @Peter Hosey: I just tried kToolbarDesktopFolderIcon and it's undeclared for me. Maybe it's Snow Leopard-only? – Yanik Magnan Sep 05 '09 at 19:45
  • 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 Sep 06 '09 at 01:03