Skip to content

Instantly share code, notes, and snippets.

@shevchenkoartem
Last active February 11, 2022 10:05
Show Gist options
  • Save shevchenkoartem/90a919433ad1115344d5485a9a8f7aa8 to your computer and use it in GitHub Desktop.
Save shevchenkoartem/90a919433ad1115344d5485a9a8f7aa8 to your computer and use it in GitHub Desktop.
Converts an image (e.g. PNG) to an ICNS icon-file. Inspired by https://stackoverflow.com/a/20703594
#!/bin/sh -e
#########################################
# Usage:
#########################################
# for each png file in the directory:
# sh make-icns.sh
#########################################
# for a specific file:
# sh make-icns.sh filename.ext
#########################################
trap somethingFailed ERR
function somethingFailed() {
echo "Something has failed. The job has bot been completed."
exit 1
}
if [ $# -eq 0 ]
then
echo "Running script for each PNG file in the current directory..."
for f in *.png ; do sh $0 "$f" ; done
exit;
fi
mkdir $1.iconset
sips -z 16 16 $1 --out $1.iconset/icon_16x16.png
sips -z 32 32 $1 --out $1.iconset/icon_16x16@2x.png
sips -z 32 32 $1 --out $1.iconset/icon_32x32.png
sips -z 64 64 $1 --out $1.iconset/icon_32x32@2x.png
sips -z 128 128 $1 --out $1.iconset/icon_128x128.png
sips -z 256 256 $1 --out $1.iconset/icon_128x128@2x.png
sips -z 256 256 $1 --out $1.iconset/icon_256x256.png
sips -z 512 512 $1 --out $1.iconset/icon_256x256@2x.png
sips -z 512 512 $1 --out $1.iconset/icon_512x512.png
cp $1 $1.iconset/icon_512x512@2x.png
iconutil -c icns $1.iconset
rm -R $1.iconset
echo "$1.icns is ready!\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment