Posted on 02-10-2019 01:42 PM
So I needed a programatic way to convert a PNG to an ICNS.
Here's what I came up with on Saturday:
#!/bin/sh
# Use this script to create an ICNS from a *square* PNG that is 512x512 or larger.
# To run this script: <script> <pngFile> <icnsName>
# For example: ~/createICNSfile.sh ~/pngFile.png icnsName
# Script will open ~/Desktop/ICONS/ when it is done.
# 20190209 DM
CURRENTUSER=$( python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");' )
mkdir -p /Users/"$CURRENTUSER"/Desktop/ICNS/"$2"/"$2".iconset
/usr/bin/sips --resampleHeightWidthMax 16 "$1" --out /Users/"$CURRENTUSER"/Desktop/ICNS/"$2"/"$2".iconset/icon_16x16.png
/usr/bin/sips --resampleHeightWidthMax 32 "$1" --out /Users/"$CURRENTUSER"/Desktop/ICNS/"$2"/"$2".iconset/icon_16x16@2x.png
/usr/bin/sips --resampleHeightWidthMax 32 "$1" --out /Users/"$CURRENTUSER"/Desktop/ICNS/"$2"/"$2".iconset/icon_32x32.png
/usr/bin/sips --resampleHeightWidthMax 64 "$1" --out /Users/"$CURRENTUSER"/Desktop/ICNS/"$2"/"$2".iconset/icon_32x32@2x.png
/usr/bin/sips --resampleHeightWidthMax 128 "$1" --out /Users/"$CURRENTUSER"/Desktop/ICNS/"$2"/"$2".iconset/icon_128x128.png
/usr/bin/sips --resampleHeightWidthMax 256 "$1" --out /Users/"$CURRENTUSER"/Desktop/ICNS/"$2"/"$2".iconset/icon_128x128@2x.png
/usr/bin/sips --resampleHeightWidthMax 256 "$1" --out /Users/"$CURRENTUSER"/Desktop/ICNS/"$2"/"$2".iconset/icon_256x256.png
/usr/bin/sips --resampleHeightWidthMax 512 "$1" --out /Users/"$CURRENTUSER"/Desktop/ICNS/"$2"/"$2".iconset/icon_256x256@2x.png
/usr/bin/sips --resampleHeightWidthMax 512 "$1" --out /Users/"$CURRENTUSER"/Desktop/ICNS/"$2"/"$2".iconset/icon_512x512.png
/usr/bin/sips --resampleHeightWidthMax 1024 "$1" --out /Users/"$CURRENTUSER"/Desktop/ICNS/"$2"/"$2".iconset/icon_512x512@2x.png
/usr/bin/iconutil --convert icns /Users/"$CURRENTUSER"/Desktop/ICNS/"$2"/"$2".iconset
open /Users/"$CURRENTUSER"/Desktop/ICNS/"$2"
exit 0
On Sunday I stumbled upon Jamf's script on GitHub.
I'll be in purgatory if anyone needs me.
Well done Jamf!