Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash function to build an .icns from a .png, with no dependencies
function make_icns {
local file="${1}"
local iconset="$(mktemp -d)"
local output_icon="$(mktemp).icns"
for size in {16,32,64,128,256,512}; do
sips --resampleHeightWidth "${size}" "${size}" "${file}" --out "${iconset}/icon_${size}x${size}.png" &> /dev/null
sips --resampleHeightWidth "$((size * 2))" "$((size * 2))" "${file}" --out "${iconset}/icon_${size}x${size}@2x.png" &> /dev/null
done
mv "${iconset}" "${iconset}.iconset"
iconutil --convert icns "${iconset}.iconset" --output "${output_icon}"
echo "${output_icon}" # So its path is returned when the function ends
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.