Why setting image as its own icon with sips result a blurred icon? Are there any alternatives? I've successfully changed icons using the procedure described in an another question: Changing or setting a file or folder icon programmatically. Either my sips (or Finder) got broken afterwards or I just zoomed in for the first time (it seems the icon is sharp from ≈100x100 downwards), but, anyway, the icon that sips -i image.png creates is blurry/pixelated:



What I did before the blurrification:

$ cp FIN-2.png FIN-3.png
$ sips -i FIN-3.png


So FIN-2 and FIN-3 are the same. FIN-2 is a 512x512 PNG-file

Furthermore: using sips breaks all further attempts when trying to set a custom icon even with any GUI method and with any file in any folder.

Only cure is to delete ~/Library/Caches/com.apple.finder/ and restart Finder. Then changing icon via GUI (drag&amp;drop, copy&amp;paste) works normally with any file.



Two main questions—and answering to either one probably solves the problem close enough for me:


How can I set an image as an icon programmatically without using sips -i (= sips --addIcon) in the process? (again, refer to the other question for more comprehensive info)


Shell (bash) or AppleScript is preferred
I could convert the PNG to e.g. ICNS if needed.

Is sips broken? Why/How? Can it be fixed; how? (Or is it the Finder? Or something else?)
I think I've found a workaround!

First off, install osxutils bundle which is a bit dated (2005) but nevertheless it works. (see the osxutils contents and man pages)

Prepare the PNG to ICNS†—ironically you can use sips‡. Then use seticon from the osxutils bundle to change the icon:

$ sips -s format icns FIN.png --out FIN.icns
$ seticon -d FIN.icns FIN.png


The seticon also changes the file's attributes, ie. using SetFile -a C isn't necessary.



†: Using a PNG as a source file for seticon changes the icon to a generic PNG icon, even with -d option. Furthermore, using seticon FIN.icns FIN.png changes the icon to a generic ICNS icon. (Consult the seticon's man pages)

‡: NB: the source file must be a square and possible side-lengths are: 16, 32, 48, 128, 256 and 512.