2018-04-26 11:42:03 +00:00
|
|
|
#!/usr/bin/env bash
|
2016-01-27 02:22:22 +00:00
|
|
|
|
2016-03-10 07:41:25 +00:00
|
|
|
### USAGE
|
2016-01-27 02:22:22 +00:00
|
|
|
|
2016-03-10 07:50:45 +00:00
|
|
|
# ./convertToIcns <input png> <outp icns>
|
2016-01-27 02:22:22 +00:00
|
|
|
# Example
|
2016-03-10 07:50:45 +00:00
|
|
|
# ./convertToIcns ~/sample.png ~/Desktop/converted.icns
|
2016-01-27 02:22:22 +00:00
|
|
|
|
2016-03-10 07:41:25 +00:00
|
|
|
# exit the shell script on error immediately
|
|
|
|
set -e
|
|
|
|
|
2016-01-27 02:22:22 +00:00
|
|
|
# Exec Paths
|
2018-04-26 11:42:03 +00:00
|
|
|
HAVE_IMAGEMAGICK=
|
|
|
|
HAVE_ICONUTIL=
|
|
|
|
HAVE_SIPS=
|
|
|
|
|
|
|
|
type convert &>/dev/null && HAVE_IMAGEMAGICK=true
|
|
|
|
type iconutil &>/dev/null && HAVE_ICONUTIL=true
|
|
|
|
type sips &>/dev/null && HAVE_SIPS=true
|
|
|
|
|
|
|
|
[[ -z "$HAVE_ICONUTIL" ]] && { echo >&2 "Cannot find required iconutil executable"; exit 1; }
|
|
|
|
[[ -z "$HAVE_IMAGEMAGICK" && -z "$HAVE_SIPS" ]] && { echo >&2 "Cannot find required image converter, please install sips or imagemagick"; exit 1; }
|
2016-01-27 02:22:22 +00:00
|
|
|
|
|
|
|
# Parameters
|
2018-04-26 11:42:03 +00:00
|
|
|
SOURCE="$1"
|
|
|
|
DEST="$2"
|
2016-01-27 02:22:22 +00:00
|
|
|
|
2016-03-08 15:58:38 +00:00
|
|
|
# Check source and destination arguments
|
2016-01-27 02:22:22 +00:00
|
|
|
if [ -z "${SOURCE}" ]; then
|
|
|
|
echo "No source image specified"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-02-04 06:43:08 +00:00
|
|
|
if [ -z "${DEST}" ]; then
|
|
|
|
echo "No destination specified"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-04-26 11:42:03 +00:00
|
|
|
TEMP_DIR="$(mktemp -d)"
|
|
|
|
ICONSET="${TEMP_DIR}/converted.iconset"
|
2016-01-27 02:22:22 +00:00
|
|
|
|
2016-03-10 07:41:25 +00:00
|
|
|
function cleanUp() {
|
|
|
|
rm -rf "${TEMP_DIR}"
|
|
|
|
}
|
2016-03-08 15:58:38 +00:00
|
|
|
|
2016-03-10 07:41:25 +00:00
|
|
|
trap cleanUp EXIT
|
2016-03-08 15:58:38 +00:00
|
|
|
|
2018-04-26 11:42:03 +00:00
|
|
|
"${BASH_SOURCE%/*}/convertToIconset" "${SOURCE}" "${ICONSET}"
|
2016-01-27 02:22:22 +00:00
|
|
|
|
|
|
|
# Create an icns file lefrom the iconset
|
2016-03-09 06:22:11 +00:00
|
|
|
iconutil -c icns "${ICONSET}" -o "${DEST}"
|
2016-01-27 02:22:22 +00:00
|
|
|
|
2016-03-10 07:41:25 +00:00
|
|
|
trap - EXIT
|
|
|
|
cleanUp
|