如何为非应用程序的 bundle 设置图标?我尝试使用 CFBundleIconFile,但它不起作用(尽管如果我只是将包扩展名更改为 .app
,图标就会更改为所需的图标)。是否还有另一个键,或者唯一的方法是为目录设置图标?如果是这样,是否已经有一些脚本可以从命令行执行此操作(Xcode 运行脚本)?
最佳答案
如果您需要从 CLI 执行此操作...则涉及更多...
首先,您需要将 CFBundleIconFile
字符串添加到您的 bundle 中
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.
也就是说,您要么需要 ICNS 文件,要么可以 follow these instructions从这里Utility (which includes its source code)通过命令行从图像文件生成 ICNS。
$ ./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.
关于macos - 设置非应用程序 mac os x bundle 的图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4806085/