Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

blurry icon

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&drop, copy&paste) works normally with any file.


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

  1. 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.
  2. Is sips broken? Why/How? Can it be fixed; how? (Or is it the Finder? Or something else?)
share|improve this question
up vote 1 down vote accepted

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.

share|improve this answer

Strangely enough the best solution seems to be not to use Apple's own tools but the Python code because it has 3 advantages not being limited by:

  • output file resolution
    (it works till 1024x1024)
  • input file format
    (tried with ICNS and PNG)
  • permissions to install
    (define it as a function)
share|improve this answer
    
Welcome to Ask Different! I'd recommend taking a look at this answer to a similar question that uses preinstalled utilities but supports features not supported by previous apps. Not sure why it's blurry in this example. – JMY1000 May 20 at 2:11
    
Maybe I am quite new to this subsite, but not the topic, take a look at stackoverflow.com/a/31150333/1535581. What are the features you refer to? It's blurry because it uses sips -i that seems to be limited at a resolution of 256x256 pixels at the moment. – dardo82 May 22 at 2:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.