Skip to content

Instantly share code, notes, and snippets.

@clj
Created October 13, 2017 23:44
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clj/c8a3d74ae99e53792512f05f01832037 to your computer and use it in GitHub Desktop.
Save clj/c8a3d74ae99e53792512f05f01832037 to your computer and use it in GitHub Desktop.
Script to generate an OS X .icns file from an .svg file using the Inkscape cli
#!/usr/bin/env bash
###
# Adapted from: https://stackoverflow.com/a/20703594
###
if [ -z "${1+set}" ]; then
echo "Pass path to the inkscape command as first argument"
exit 1
fi
if [ -z "${2+set}" ]; then
echo "Pass svg file as second argument"
exit 1
fi
if [ -z "${3+set}" ]; then
echo "Pass output name (w/o .icns) as third argument"
exit 1
fi
inkscape=$1
svg_file=$2
output_name=$3
set -e
mkdir $output_name.iconset
$inkscape -z -e "$PWD/$output_name.iconset/icon_16x16.png" -w 16 -h 16 "$PWD/$svg_file"
$inkscape -z -e "$PWD/$output_name.iconset/icon_16x16@2x.png" -w 32 -h 32 "$PWD/$svg_file"
$inkscape -z -e "$PWD/$output_name.iconset/icon_32x32.png" -w 32 -h 32 "$PWD/$svg_file"
$inkscape -z -e "$PWD/$output_name.iconset/icon_32x32@2x.png" -w 64 -h 64 "$PWD/$svg_file"
$inkscape -z -e "$PWD/$output_name.iconset/icon_128x128.png" -w 128 -h 128 "$PWD/$svg_file"
$inkscape -z -e "$PWD/$output_name.iconset/icon_128x128@2x.png" -w 256 -h 256 "$PWD/$svg_file"
$inkscape -z -e "$PWD/$output_name.iconset/icon_256x256.png" -w 256 -h 256 "$PWD/$svg_file"
$inkscape -z -e "$PWD/$output_name.iconset/icon_256x256@2x.png" -w 512 -h 512 "$PWD/$svg_file"
$inkscape -z -e "$PWD/$output_name.iconset/icon_512x512.png" -w 512 -h 512 "$PWD/$svg_file"
$inkscape -z -e "$PWD/$output_name.iconset/icon_512x512@2x.png" -w 1024 -h 1024 "$PWD/$svg_file"
iconutil -c icns "$output_name.iconset"
rm -R "$output_name.iconset"
@SgtPooki
Copy link

SgtPooki commented May 6, 2022

thanks for the handy script =D

> ./make-icns.sh inkscape public/ipfs-logo.svg ipfs-logo
Warning: Option --without-gui= is deprecated
Unknown option -e

> inkscape --version
Inkscape 1.1.2 (b8e25be8, 2022-02-05)

Here is what I used:

#!/usr/bin/env bash

###
# Pulled from: https://gist.github.com/clj/c8a3d74ae99e53792512f05f01832037
###

if [ -z "${1+set}" ]; then
  echo "Pass path to the inkscape command as first argument"
  exit 1
fi
if [ -z "${2+set}" ]; then
  echo "Pass svg file as second argument"
  exit 1
fi
if [ -z "${3+set}" ]; then
  echo "Pass output name (w/o .icns) as third argument"
  exit 1
fi

inkscape=$1
svg_file=$2
output_name=$3

set -e
mkdir $output_name.iconset
$inkscape -o "$PWD/$output_name.iconset/icon_16x16.png"      -w   16 -h   16 "$PWD/$svg_file"
$inkscape -o "$PWD/$output_name.iconset/icon_16x16@2x.png"   -w   32 -h   32 "$PWD/$svg_file"
$inkscape -o "$PWD/$output_name.iconset/icon_32x32.png"      -w   32 -h   32 "$PWD/$svg_file"
$inkscape -o "$PWD/$output_name.iconset/icon_32x32@2x.png"   -w   64 -h   64 "$PWD/$svg_file"
$inkscape -o "$PWD/$output_name.iconset/icon_128x128.png"    -w  128 -h  128 "$PWD/$svg_file"
$inkscape -o "$PWD/$output_name.iconset/icon_128x128@2x.png" -w  256 -h  256 "$PWD/$svg_file"
$inkscape -o "$PWD/$output_name.iconset/icon_256x256.png"    -w  256 -h  256 "$PWD/$svg_file"
$inkscape -o "$PWD/$output_name.iconset/icon_256x256@2x.png" -w  512 -h  512 "$PWD/$svg_file"
$inkscape -o "$PWD/$output_name.iconset/icon_512x512.png"    -w  512 -h  512 "$PWD/$svg_file"
$inkscape -o "$PWD/$output_name.iconset/icon_512x512@2x.png" -w 1024 -h 1024 "$PWD/$svg_file"
iconutil -c icns "$output_name.iconset"
rm -R "$output_name.iconset"

@RajSolai
Copy link

Thanks a lot Guys , useful script !

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