forked from bejo/XcodeIconTagger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtagIcons.sh
executable file
·49 lines (40 loc) · 1.94 KB
/
tagIcons.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
commit=`git rev-parse --short HEAD`
version1=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${INFOPLIST_FILE}"`
version2=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${INFOPLIST_FILE}"`
version="${version1} [${version2}]"
mode=$1
tagMode="tag"
cleanupMode="cleanup"
iconsDirectory=`cd $2 && pwd`
if [ $(echo "${iconsDirectory}" | grep -E "\.appiconset$") ]; then
icons=(`grep 'filename' "${iconsDirectory}/Contents.json" | cut -f2 -d: | tr -d ',' | tr -d '\n' | tr -d '"'`)
else
icons=(`/usr/libexec/PlistBuddy -c "Print CFBundleIconFiles" "${INFOPLIST_FILE}" | grep png | tr -d '\n'`)
fi
taggerDirectory=`dirname $0`
taggerPlist="tagImage.workflow/Contents/document.wflow"
paramsPath=":actions:0:action:ActionParameters"
iconsCount=${#icons[*]}
for (( i=0; i<iconsCount; i++ ))
do
icon="$iconsDirectory/${icons[$i]}"
if [ -f $icon ]; then
height=`sips -g pixelHeight $icon | tail -n 1 | sed "s/ *pixelHeight: */ /"`
width=`sips -g pixelWidth $icon | tail -n 1 | sed "s/ *pixelWidth: */ /"`
if (( $height == $width )); then
if [ $mode == $tagMode ]; then
renderSize=$(( $width * 4 )) # for some reason it looks much better when rendering canvas are bigger than an icon
renderSize=$(( $renderSize + $width%2 )) # rendering canvas for odd sized images should also be odd
cd $taggerDirectory
/usr/libexec/PlistBuddy -c "Set $paramsPath:renderPixelsHigh $renderSize" -c "Set $paramsPath:renderPixelsWide $renderSize" $taggerPlist
automator -D text="$version"$'\n'"$commit" -D image="$icon" -i tagImage.qtz tagImage.workflow > /dev/null
git checkout $taggerPlist
sips --cropToHeightWidth $height $width tagImage.png > /dev/null
mv tagImage.png $icon
elif [ $mode == $cleanupMode ]; then
git checkout $icon
fi
fi
fi
done