How to manually create icns files using iconutil?

| | August 5, 2015

When I’m validating my app I get this error:

the application bundle does not contain an icon in ICNS format, containing both a 512x512 and a 512x512@2x image.

I use to make the icns icons with Img2icns app and till today it always worked good. But now I’m getting that error and there’s no way to make it work. I tryed to put two PNG files togheter (512x512 and 1024x1024) in Img2icns but I always get the error. I also tryed to follow instructions on OS X Human Interface Guideline of Apple but when I try to make the icon sets I get this terminal error:

-bash: syntax error near unexpected token ‘newline’

I am not very good with terminal command and so maybe I’m doing something wrong. I wrote:

iconutil -c icns </Users/myname/SDK Mac Apps/MyApp/grafica/icon.iconset>

If anyone could help it would be very much appreciated. Thanks, Massy.

7 Responses to “How to manually create icns files using iconutil?”

  1. Additional comment, when you create .icns file, you need to rename all the pic files with prefix “icon_“, otherwise, iconutil will fail with error message: “.iconset:error: Failed to generate ICNS.” which is not informative at all.

  2. I’ve refactored @Henry’s script to make it look better:

    #!/bin/zsh
    NAME=$(basename $1 .png); DIR="$NAME.iconset"
    mkdir -pv $DIR
    for m r in 'n' '' '((n+1))' '@2x'; do
        for n in $(seq 4 9 | grep -v 6); do
            p=$((2**$m)); q=$((2**$n))
            OUT="$DIR/icon_${q}x${q}${r}.png"
            sips -z $p $p $1 --out $OUT
        done
    done
    iconutil -c icns $DIR
    rm -frv $DIR
    
  3. Here’s a script to convert a 1024×1024 png (named “Icon1024.png”) to the required icns file. Save it to a filed called “CreateICNS.src” in the folder where your png file is then in terminal “cd” to the same folder and type “source CreateICNS.src” to call it:

    mkdir MyIcon.iconset
    sips -z 16 16     Icon1024.png --out MyIcon.iconset/icon_16x16.png
    sips -z 32 32     Icon1024.png --out MyIcon.iconset/icon_16x16@2x.png
    sips -z 32 32     Icon1024.png --out MyIcon.iconset/icon_32x32.png
    sips -z 64 64     Icon1024.png --out MyIcon.iconset/icon_32x32@2x.png
    sips -z 128 128   Icon1024.png --out MyIcon.iconset/icon_128x128.png
    sips -z 256 256   Icon1024.png --out MyIcon.iconset/icon_128x128@2x.png
    sips -z 256 256   Icon1024.png --out MyIcon.iconset/icon_256x256.png
    sips -z 512 512   Icon1024.png --out MyIcon.iconset/icon_256x256@2x.png
    sips -z 512 512   Icon1024.png --out MyIcon.iconset/icon_512x512.png
    cp Icon1024.png MyIcon.iconset/icon_512x512@2x.png
    iconutil -c icns MyIcon.iconset
    rm -R MyIcon.iconset
    
  4. Apple’s older Icon Composer version 2.2 works just fine, you just open the .ICNS in it, press the 1024×1024 button and add your image.

  5. These commands (entered in Terminal) worked for me to convert an old icns file to the new format:

    cd Folder_With_Icns_File
    iconutil -c iconset Your_Icon_Name.icns 
    rm Your_Icon_Name.icns 
    iconutil -c icns Your_Icon_Name.iconset
    rm -R Your_Icon_Name.iconset
    
  6. When I’m validating my app I get this error:

    the application bundle does not contain an icon in ICNS format, containing both a 512×512 and a 512×512@2x image.

    I am not very good with terminal command and so maybe I’m doing something wrong. I wrote:

    iconutil -c icns </Users/myname/SDK Mac Apps/MyApp/grafica/icon.iconset>
    

    For one thing, as I mentioned in a comment on Anne’s answer, you probably don’t need to use iconutil. You should be able to just add the iconset to your project and let Xcode convert it for you as part of the build.

    Either way, this may be your problem:

    I tryed to put two PNG files togheter (512×512 and 1024×1024) … but I always get the error.

    There is no 1024 by 1024 point size. The 1024 by 1024 pixel element (which was 1024 points before Mountain Lion) is now used for 512 by 512 points @2x.

    Your PNG file must be named appropriately: icon_512x512@2x.png

  7. Checkout the following instructions (link):

    Use iconutil to Create an icns File Manually

    The iconutil command-line tool converts iconset folders to deployment-ready, high-resolution icns files. (You can find complete documentation for this tool by entering man iconutil in Terminal.) Using this tool also compresses the resulting icns file, so there is no need for you to perform additional compression.

    To convert a set of icons to an icns file

    Enter this command into the Terminal window:

    iconutil -c icns <iconset filename>

    where <iconset filename> is the path to the folder containing the set of icons you want to convert to icns. The output is written to the same location as the iconset file, unless you specify an output file as shown:

    iconutil -c icns -o <icon filename> <iconset filename>

    In other words, you need to replace <iconset filename> by the path:

    /Users/myname/SDK Mac Apps/MyApp/grafica/icon.iconset
    

    Since the path contains spaces, you need to use double quotes, for example:

    iconutil -c icns "/Users/myname/SDK Mac Apps/MyApp/grafica/icon.iconset"
    

    This command should work properly.

Leave a Reply