Here's my understanding, which is partly conjectural and related to implementation details:
Dock runs in a separate process, and you cannot pass arbitrary NSImage
trivially across the process border from your application to the Dock. There are only two types of images that can be transferred properly: standard system icons and icons in your resource pack. But I do not think that NSImage
does the necessary spells for any of them.
So you have to use Carbon. In particular, you need to use SetMenuItemIconHandle
with kMenuSystemIconSelectorType
(covers Carbon IconRef
s obtained with GetIconRef
) or kMenuIconResourceType
( CFString
, which refer to the .icns
file in the Resources folder of your application).
The corresponding headers are <HIToolbox/MacApplication.h>
(for GetApplicationDockTileMenu
), <HIToolbox/Menus.h>
(for SetMenuItemIconHandle
) and <HIServices/Icons.h>
, (for GetIconRef
if you use system icons).
Unconfirmed, but it should look something like this:
#include <Carbon/Carbon.h> SetMenuItemIconHandle( GetApplicationDockTileMenu(), [dockMenu indexOfItem:dockMenuItem], kMenuIconResourceType, (Handle) CFSTR("icon.icns") );
Perhaps this is not so simple; some of them can only be 32-bit.
source share