5

How to set icon for bundle which 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)?

tig
  • 25,841
  • 10
  • 64
  • 96

2 Answers2

2

Visual documentation of the process of copying and pasting an icon in the Finder

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.

Alex Gray
  • 16,007
  • 9
  • 96
  • 118
0

Answer from similar (duplicate) question:

[[NSWorkspace sharedWorkspace]
  setIcon:(NSImage *)image
  forFile:(NSString *)bundlePath
  options:0];
Community
  • 1
  • 1
yairchu
  • 23,680
  • 7
  • 69
  • 109
  • This solution worked for me, however it didn't change the file inside `/Contents/Resources/appicon.icns` in my app bundle. Even if i restart it uses the new icon i set it to, but my old image remains in the Resources folder, making me think some tricky stuff is going on other then a simple refresh. Can you please share your thoughts on this @yairchu – Noitidart Jan 13 '15 at 21:04
  • 1
    @Noitidart: I found it in the duplicate question (linked) as I mentioned. "Fruity Geek" gave the answer over there and links to Apple's reference, I don't have any further details.. – yairchu Jan 13 '15 at 22:27
  • Thanks I commented there asking him :) – Noitidart Jan 13 '15 at 23:22
  • This is like doing it from the Get Info window in Finder. It doesn't change the icon file in the bundle. It won't persist when moving to another machine will it? – uchuugaka May 16 '18 at 03:53