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
@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