Created
August 29, 2019 06:33
-
-
Save jlehikoinen/a1e5424e97519c49c80888593c25c077 to your computer and use it in GitHub Desktop.
Create Xcode iconset for macOS app from a 1024x1024 sized png file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# ================================================ | |
# create_xcode_icns.sh | |
# | |
# Create Xcode iconset for macOS app from a 1024x1024 sized png file | |
# | |
# Drag png file to Terminal window to get the file path as a parameter for the script | |
# Iconset will be created to the same folder where the original icon is | |
# Import (drag&drop) icns file to Xcode | |
# Edit Info.plist -> Icon file: icons_for_xcode | |
# ================================================ | |
set -o nounset # Exit script if variable is not set | |
### Vars | |
iconset_name="icons_for_xcode.iconset" | |
number_of_parameters=$# | |
all_parameters=( "$@" ) | |
### Commands | |
sips="/usr/bin/sips" | |
### | |
function usage() { | |
echo "Usage: $0 path/to/original-1024.png" | |
} | |
function preflight_checks() { | |
# Check parameters | |
if [ $number_of_parameters -eq 0 ]; then | |
echo "ERROR: Missing parameter, png file path required." | |
usage | |
exit 1 | |
else | |
orig_icon_file="${all_parameters[0]}" | |
target_folder=$(dirname "$orig_icon_file") | |
iconset_path="${target_folder}/${iconset_name}" | |
fi | |
if [[ ! -f "$orig_icon_file" ]]; then | |
echo "ERROR: File not found: ${orig_icon_file}" | |
usage | |
exit 1 | |
fi | |
} | |
function create_icon_files() { | |
# Create temp dir | |
/bin/mkdir -p "$iconset_path" | |
# Create files | |
$sips -z 16 16 "$orig_icon_file" --out "$iconset_path"/icon_16x16.png | |
$sips -z 32 32 "$orig_icon_file" --out "$iconset_path"/[email protected] | |
$sips -z 32 32 "$orig_icon_file" --out "$iconset_path"/icon_32x32.png | |
$sips -z 64 64 "$orig_icon_file" --out "$iconset_path"/[email protected] | |
$sips -z 128 128 "$orig_icon_file" --out "$iconset_path"/icon_128x128.png | |
$sips -z 256 256 "$orig_icon_file" --out "$iconset_path"/[email protected] | |
$sips -z 256 256 "$orig_icon_file" --out "$iconset_path"/icon_256x256.png | |
$sips -z 512 512 "$orig_icon_file" --out "$iconset_path"/[email protected] | |
$sips -z 512 512 "$orig_icon_file" --out "$iconset_path"/icon_512x512.png | |
/bin/cp "$orig_icon_file" "$iconset_path"/[email protected] | |
# Convert .iconset -> .icns | |
/usr/bin/iconutil -c icns "$iconset_path" | |
# Delete temp folder | |
# /bin/rm -r "$iconset_path" | |
} | |
# | |
preflight_checks | |
create_icon_files | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment