Skip to content

Instantly share code, notes, and snippets.

@mark-ingenosity
Last active March 31, 2026 12:15
Show Gist options
  • Select an option

  • Save mark-ingenosity/6b9a29123e3df925e56029917cfb3f3a to your computer and use it in GitHub Desktop.

Select an option

Save mark-ingenosity/6b9a29123e3df925e56029917cfb3f3a to your computer and use it in GitHub Desktop.
[BASH: Image Conversion: SVG to Mac ICNS] #convert #image #file_type #bash #script #icon
#!/bin/bash
# iterate over the svg files fed into on the command line
for svgfile in "$@"
do
name=${f%.*}
ext=${f##*.}
echo "Processing $name ..."
set -e
mkdir $name.iconset
# run inkscape from the command line to generate the iconset formatted for icns
inkscape -z -e "$PWD/$name.iconset/icon_16x16.png" -w 16 -h 16 "$PWD/$svgfile"
inkscape -z -e "$PWD/$name.iconset/icon_16x16@2x.png" -w 32 -h 32 "$PWD/$svgfile"
inkscape -z -e "$PWD/$name.iconset/icon_32x32.png" -w 32 -h 32 "$PWD/$svgfile"
inkscape -z -e "$PWD/$name.iconset/icon_32x32@2x.png" -w 64 -h 64 "$PWD/$svgfile"
inkscape -z -e "$PWD/$name.iconset/icon_128x128.png" -w 128 -h 128 "$PWD/$svgfile"
inkscape -z -e "$PWD/$name.iconset/icon_128x128@2x.png" -w 256 -h 256 "$PWD/$svgfile"
inkscape -z -e "$PWD/$name.iconset/icon_256x256.png" -w 256 -h 256 "$PWD/$svgfile"
inkscape -z -e "$PWD/$name.iconset/icon_256x256@2x.png" -w 512 -h 512 "$PWD/$svgfile"
inkscape -z -e "$PWD/$name.iconset/icon_512x512.png" -w 512 -h 512 "$PWD/$svgfile"
inkscape -z -e "$PWD/$name.iconset/icon_512x512@2x.png" -w 1024 -h 1024 "$PWD/$svgfile"
# run osx iconutil app to convert the iconset to icns format
iconutil -c icns "$name.iconset"
#cleanup
rm -R "$name.iconset"
done
echo "Done."
@Jaaap

Jaaap commented Dec 6, 2025

Copy link
Copy Markdown

Thank you for your script!
I had to change it a little to get it to work on macOS Tahoe 26.1 / GNU Bash 3.2.57

#!/bin/bash

# iterate over the svg files fed into on the command line
for svgfile in "$@"
do
	filename=$(basename -- "$svgfile")
	ext="${filename##*.}"
	name="${filename%.*}"

	echo "Processing $name ..."
	set -e
	mkdir "$name.iconset"

	# run inkscape from the command line to generate the iconset formatted for icns
	inkscape --export-filename="$PWD/$name.iconset/icon_16x16.png"      --export-width=16 "$PWD/$svgfile"
	inkscape --export-filename="$PWD/$name.iconset/icon_16x16@2x.png"   --export-width=32 "$PWD/$svgfile"
	inkscape --export-filename="$PWD/$name.iconset/icon_32x32.png"      --export-width=32 "$PWD/$svgfile"
	inkscape --export-filename="$PWD/$name.iconset/icon_32x32@2x.png"   --export-width=64 "$PWD/$svgfile"
	inkscape --export-filename="$PWD/$name.iconset/icon_128x128.png"    --export-width=128 "$PWD/$svgfile"
	inkscape --export-filename="$PWD/$name.iconset/icon_128x128@2x.png" --export-width=256 "$PWD/$svgfile"
	inkscape --export-filename="$PWD/$name.iconset/icon_256x256.png"    --export-width=256 "$PWD/$svgfile"
	inkscape --export-filename="$PWD/$name.iconset/icon_256x256@2x.png" --export-width=512 "$PWD/$svgfile"
	inkscape --export-filename="$PWD/$name.iconset/icon_512x512.png"    --export-width=512 "$PWD/$svgfile"
	inkscape --export-filename="$PWD/$name.iconset/icon_512x512@2x.png" --export-width=1024 "$PWD/$svgfile"

	# run osx iconutil app to convert the iconset to icns format
	iconutil -c icns "$name.iconset"

	#cleanup
	rm -R "$name.iconset"
done
echo "Done."

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