I compile a Mac OSX bundle, called MyBundle.bundle, which is used as a plugin for another application. I want the bundle have a unique icon and so I set the Info.plist file to say:
<key>CFBundleIconFile</key>
<string>MyIcon.icns</string>
and place the file MyIcon.icns in the bundle's MyBundle.bundle/Contents/Resources folder.
This does not work, the finder show a generic icon for the bundle and ignores the specified MyIcon.icns file. If I change the bundle's extension from .bundle to .app the icon immediately shows - so I know the Info.plist is correct.
I found a work around that simulates a user doing copy and paste of an icon on the bundle:
I add the icon as a resource of type "icns" and id -16455 to the bundle's .rsrc file.
I than call
/Developer/Tools/SetFile -a BC MyBundle.bundle
This works, but is really lame. Starting in Mac OS 10.8 SetFile takes forever to execute.
My question: Is there away to force the Finder to show the bundle's icon without such hacks?
BTW: There is a question on same subject: Set icon of non app mac os x bundle; but the only answer there instructs on how to create an icon, and does not help with the problem.
You can use NSWorkspace
[[NSWorkspace sharedWorkspace] setIcon:(NSImage *)image forFile:(NSString *)fullPath options:(NSWorkspaceIconCreationOptions)options]
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSWorkspace_Class/Reference/Reference.html
This solution will associate the same icon for all your .bundle. I'm not sure this what you need (or if you need a specific/different icon for each of your .bundle).
If you can modify the app bundle: you can define a document type to associate with the app. To do so you have to edit app package:
TheOtherApp.app/Contents/Resources/MyIcon.icns
edit the TheOtherApp.app/Contents/Info.plist
and add something like this:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>TheOtherApp Plugin</string>
<key>CFBundleTypeRole</key>
<string>None</string>
<key>CFBundleTypeIconFile</key>
<string>FlexoDocument.icns</string>
<key>CFBundleTypeExtensions</key>
<array>
<string>bundle</string>
</array>
<key>LSTypeIsPackage</key>
<string>true</string>
</dict>
</array>
more Info about CFBundleDocumentTypes on developer.apple.com
You may need to relaunch the finder and/or the app to see the effect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With