开发者

Set icon of non app mac os x bundle

How to set icon for bundle whi开发者_JAVA技巧ch is not an app? I tried using CFBundleIconFile, but it doesn't work (though if I just change bundle extension to .app, icon is changed to desired one). Is there another key, or the only way is to set icon for directory? If so, is there already some script to do this from command line (Xcode run script)?


Set icon of non app mac os x bundle

If you need to do it from CLI... It's a bit more involved...

First, you need to add a CFBundleIconFile string to your bundle's

YourThing.bundle/Contents/Info.plist

Here's where the developer gets to specify a custom icon for the bundle. This key contains the name of a file in the bundle's Resources folder that holds the icons. TextEdit keeps its icon in a file called Edit.icns file, but there's no rule about what the name of the file must be.

That said, you either need an ICNS file, or can follow these instructions from this Utility (which includes its source code) that generates ICNS's from image files via the command line..

$ ./makeicns 

Usage: makeicns [k1=v1] [k2=v2] ...

Keys and values include: 512: Name of input image for 512x512 variant of icon 256: Name of input image for 256x256 variant of icon 128: Name of input image for 128x128 variant of icon 32: Name of input image for 32x32 variant of icon 16: Name of input image for 16x16 variant of icon in: Name of input image for all variants not having an explicit name out: Name of output file, defaults to first nonempty input name, but with icns extension

Examples:

  makeicns -512 image.png -32 image.png

Creates image.icns with only a 512x512 and a 32x32 variant.

  makeicns -in myfile.jpg -32 otherfile.png -out outfile.icns

Creates outfile.icns with sizes 512, 256, 128, and 16 containing data from myfile.jpg and with size 32 containing data from otherfile.png.


Answer from similar (duplicate) question:

[[NSWorkspace sharedWorkspace]
  setIcon:(NSImage *)image
  forFile:(NSString *)bundlePath
  options:0];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜