Skip to content

Instantly share code, notes, and snippets.

@jamieweavis
Last active October 10, 2024 23:10
Show Gist options
  • Save jamieweavis/b4c394607641e1280d447deed5fc85fc to your computer and use it in GitHub Desktop.
Save jamieweavis/b4c394607641e1280d447deed5fc85fc to your computer and use it in GitHub Desktop.
How to create an .icns macOS app icon

How to create an .icns macOS app icon

How to make an application icon for macOS using iconset & iconutil

Steps

Saving images

Save your app icon with the following names & dimensions:

Name Dimensions
icon_16x16.png 16x16
[email protected] 32x32
icon_32x32.png 32x32
[email protected] 64x64
icon_128x128.png 128x128
[email protected] 256x256
icon_256x256.png 256x256
[email protected] 512x512
icon_512x512.png 512x512
[email protected] 1024x1024

Creating an .iconset

  1. Move all of the images into a new folder
  2. Rename the folder to: icon.iconset
  3. Confirm the file extension when prompted

This will convert the folder of images into an iconset, this can be verified by quick looking with the spacebar - a resizable preview of your icon should now appear.

Converting to .icns

  1. Navigate to the directory containing your icon.iconset in the terminal
  2. Run iconutil with the following command: iconutil -c icns icon.iconset
  3. Your icon.icns will be generated in the current directory
@erwinagpasa
Copy link

➜ icon.iconset iconutil -c icns icon.iconset
icon.iconset:Iconset not found.
➜ icon.iconset

@jamieweavis
Copy link
Author

@erwinagpasa the command is iconutil

Try running iconutil -c icns icon.iconset

@erwinagpasa
Copy link

Thanks bro

@irfanawanens
Copy link

irfanawanens commented Dec 8, 2022

iconutil -c icns icon.iconset didn't work for me...
here is the error:
icon.iconset:Failed to generate ICNS.

@jamieweavis
Copy link
Author

@irfanawanens
Copy link

Yes,
Thank for the comments,
the issue was the the alpha of png files,
I rest the icons with alpha, and then it worked for me,
Thanks @jamieweavis

@MichaelBelousov
Copy link

here's a bash snippet for automating making an icns from some other image using imagemagick which you can brew install.

output_path=/tmp/output.iconset

# the convert command comes from imagemagick
for size in 16 32 64 128 256; do
  half="$(($size / 2))"
  convert my_large_image.png -resize x$size $output_path/icon_${size}x${size}.png
  convert my_large_image.png -resize x$size $output_path/icon_${half}x${half}@2x.png
done

iconutil -c icns $output_path

@EasyG0ing1
Copy link

Just an FYI, I wrote a program based on these instructions that does all the work for you.

@danneu
Copy link

danneu commented Apr 8, 2023

Now I have an .icns package but I've been struggling for 20min to add it to Xcode. 😄 Not even Assets.xcassets menu lets you import a .icns file.

@EasyG0ing1
Copy link

EasyG0ing1 commented Apr 11, 2023

Now I have an .icns package but I've been struggling for 20min to add it to Xcode. 😄 Not even Assets.xcassets menu lets you import a .icns file.

@danneu The irony cannot be ignored ... ☺

@rakkesh
Copy link

rakkesh commented Aug 23, 2023

brew install is an overkill, just for creating an app icon. To convert to various sizes, simply run -

$ sips -z <Y> <Y> Icon1024.png --out icon.iconset/icon_<Y>x<Y>.png,
where, <Y> is the size.

Example,
$ sips -z 16 16 Icon1024.png --out icon.iconset/icon_16x16.png
$ sips -z 32 32 Icon1024.png --out icon.iconset/[email protected]

@Benitoite
Copy link

Benitoite commented Sep 11, 2023

As an applescript droplet and using sips... drag any image onto the droplet and get the resulting .icns

image-to-icns applescript droplet

on open the_files
	repeat with i from 1 to the count of the_files
		tell application "Finder"
			set myFileName to POSIX path of item i of the_files
			set exten to name extension of item i of the_files
		end tell
		set orig_path to POSIX path of (((path to me as text) & "::") as alias) as string
		set my_path to orig_path & "icon.iconset"
		do shell script "mkdir " & my_path
		do shell script "sips -z 1024 1024 " & myFileName & " -s format png --out " & my_path & "/[email protected]"
		do shell script "sips -z 512 512 " & my_path & "/[email protected] --out " & my_path & "/icon_512x512.png"
		do shell script "cp " & my_path & "/icon_512x512.png " & my_path & "/[email protected]"
		do shell script "sips -z 256 256 " & my_path & "/icon_512x512.png --out " & my_path & "/icon_256x256.png"
		do shell script "cp " & my_path & "/icon_256x256.png " & my_path & "/[email protected]"
		do shell script "sips -z 128 128 " & my_path & "/icon_256x256.png --out " & my_path & "/icon_128x128.png"
		do shell script "sips -z 64 64 " & my_path & "/icon_128x128.png --out " & my_path & "/[email protected]"
		do shell script "sips -z 32 32 " & my_path & "/[email protected] --out " & my_path & "/icon_32x32.png"
		do shell script "cp " & my_path & "/icon_32x32.png " & my_path & "/[email protected]"
		do shell script "sips -z 16 16 " & my_path & "/icon_32x32.png --out " & my_path & "/icon_16x16.png"
		do shell script "iconutil -c icns " & my_path
		do shell script "mv " & orig_path & "/icon.icns " & orig_path & "/$(basename " & myFileName & " ." & exten & ").icns"
		do shell script "rm -r " & my_path
	end repeat
end open
  • Paste into a New document in /Applications/Utilities/Script Editor and save the script as an Application

@paulrudy
Copy link

As an applescript droplet and using sips... drag any image onto the droplet and get the resulting .icns

image-to-icns applescript droplet

on open the_files
	repeat with i from 1 to the count of the_files
		tell application "Finder"
			set myFileName to POSIX path of item i of the_files
			set exten to name extension of item i of the_files
		end tell
		set orig_path to POSIX path of (((path to me as text) & "::") as alias) as string
		set my_path to orig_path & "icon.iconset"
		do shell script "mkdir " & my_path
		do shell script "sips -z 1024 1024 " & myFileName & " -s format png --out " & my_path & "/[email protected]"
		do shell script "sips -z 512 512 " & my_path & "/[email protected] --out " & my_path & "/icon_512x512.png"
		do shell script "cp " & my_path & "/icon_512x512.png " & my_path & "/[email protected]"
		do shell script "sips -z 256 256 " & my_path & "/icon_512x512.png --out " & my_path & "/icon_256x256.png"
		do shell script "cp " & my_path & "/icon_256x256.png " & my_path & "/[email protected]"
		do shell script "sips -z 128 128 " & my_path & "/icon_256x256.png --out " & my_path & "/icon_128x128.png"
		do shell script "sips -z 64 64 " & my_path & "/icon_128x128.png --out " & my_path & "/[email protected]"
		do shell script "sips -z 32 32 " & my_path & "/[email protected] --out " & my_path & "/icon_32x32.png"
		do shell script "cp " & my_path & "/icon_32x32.png " & my_path & "/[email protected]"
		do shell script "sips -z 16 16 " & my_path & "/icon_32x32.png --out " & my_path & "/icon_16x16.png"
		do shell script "iconutil -c icns " & my_path
		do shell script "mv " & orig_path & "/icon.icns " & orig_path & "/$(basename " & myFileName & " ." & exten & ").icns"
		do shell script "rm -r " & my_path
	end repeat
end open
  • Paste into a New document in /Applications/Utilities/Script Editor and save the script as an Application

Thanks for this!

Here's a version of your script that returns the .icns file to the location of the passed image file, instead of to the location of the Applescript droplet.

on open the_files
	repeat with i from 1 to the count of the_files
		tell application "Finder"
			set myFileName to POSIX path of item i of the_files
			set orig_path to POSIX path of (container of (item i of the_files) as alias)
			set exten to name extension of item i of the_files
		end tell
		set my_path to orig_path & "icon.iconset"
		do shell script "mkdir -p " & quoted form of my_path
		do shell script "sips -z 1024 1024 " & myFileName & " -s format png --out " & my_path & "/[email protected]"
		do shell script "sips -z 512 512 " & my_path & "/[email protected] --out " & my_path & "/icon_512x512.png"
		do shell script "cp " & my_path & "/icon_512x512.png " & my_path & "/[email protected]"
		do shell script "sips -z 256 256 " & my_path & "/icon_512x512.png --out " & my_path & "/icon_256x256.png"
		do shell script "cp " & my_path & "/icon_256x256.png " & my_path & "/[email protected]"
		do shell script "sips -z 128 128 " & my_path & "/icon_256x256.png --out " & my_path & "/icon_128x128.png"
		do shell script "sips -z 64 64 " & my_path & "/icon_128x128.png --out " & my_path & "/[email protected]"
		do shell script "sips -z 32 32 " & my_path & "/[email protected] --out " & my_path & "/icon_32x32.png"
		do shell script "cp " & my_path & "/icon_32x32.png " & my_path & "/[email protected]"
		do shell script "sips -z 16 16 " & my_path & "/icon_32x32.png --out " & my_path & "/icon_16x16.png"
		do shell script "iconutil -c icns " & my_path
		do shell script "mv " & orig_path & "/icon.icns " & orig_path & "/$(basename " & myFileName & " ." & exten & ").icns"
		do shell script "rm -r " & my_path
	end repeat
end open

@Mikeint0sh
Copy link

Modified the script from @MichaelBelousov

output_path=~/Desktop/tmp
mkdir output_path

# the convert command comes from imagemagick
for size in 16 32 64 128 256 512; do
  convert ~/Desktop/Logo.png -resize x$size $output_path/icon_${size}x${size}.png
done

mv $output_path ~/Desktop/icon.iconset
iconutil -c icns ~/Desktop/icon.iconset
rm -r ~/Desktop/icon.iconset

@Benitoite
Copy link

@Mikeint0sh There are still the @2x files to generate.

@angelobdev
Copy link

angelobdev commented Oct 25, 2023

@Benitoite

Here's an updated version:

#!/bin/zsh

# Checking if ImageMagick is installed...
magick_path=$(where magick)

if [[ $magick_path == *"not found"* ]]; then
  echo "Image Magick needs to be installed!"
  echo "You can install it by running 'brew install imagemagick'"
  exit
fi;


# Reading logo file name...
echo "Please insert the image file path: "
IFS=. read file extension

input_file=$(pwd)/${file}.${extension}
output_path=$(pwd)/tmp/${file}

echo "Generating icons..."

mkdir -p $output_path
for size in 16 32 128 256 512; do
  double_size=$((2*$size))

  echo "Generating ${size}x${size}"
  convert $input_file -resize ${size}x${size}\! $output_path/icon_${size}x${size}.png

  echo "Generating ${size}x${size}@2x"
  convert $input_file -resize ${double_size}x${double_size}\! $output_path/icon_${size}x${size}@2x.png
done

echo "Generating iconset..."
mv $output_path ${output_path}.iconset

echo "Generating icns file..."
iconutil -c icns ${output_path}.iconset -o ${file}.icns

echo "Cleaning..."
rm -r ./tmp

echo "Done!"

Just run the script in any directory and insert the logo file path (the larger the better).
It will automatically generate the icns file in the current folder.

@andreif
Copy link

andreif commented Nov 8, 2023

For those who don't want to install ImageMagic via brew

brew_pepsi

#!/bin/bash
set -e

test -n "$1"
name="${1%.*}"

iconset="${name}.iconset"
rm -rf "${iconset}"
mkdir -p "${iconset}"

for s in 16 32 128 256 512; do
  d=$(($s*2))
  sips -Z $s "$1" --out "${iconset}/icon_${s}x$s.png"
  sips -Z $d "$1" --out "${iconset}/icon_${s}x$s@2x.png"
done

iconutil -c icns "${iconset}" -o "${name}.icns"
rm -r "${iconset}"

save it to e.g. script.sh, and use it like

$ chmod +x script.sh
$ script.sh icon.png

@paulrudy
Copy link

paulrudy commented Nov 8, 2023

@andreif thank you! very brief

@YektaDev
Copy link

YektaDev commented Feb 6, 2024

This can be useful for step 1.

@alptugan
Copy link

Yet another app for that purpose.
It's native app, and uses built-in bash functions on Mac.
https://github.com/alptugan/icns-creator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment