-
Notifications
You must be signed in to change notification settings - Fork 8
/
build.sh
executable file
·103 lines (85 loc) · 3.27 KB
/
build.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
# Source: https://github.com/krestaino/macos-folder-icons
# get flags
while getopts 'f' flag; do
case "${flag}" in
f) NO_CACHE='true' ;;
esac
done
# cleanup build
rm -rf build/*
# set theme
THEME="system"
echo "Building for $(tput setaf 4)$THEME$(tput sgr0) theme"
DARK_FOLDER="FolderDark512x512@2x.png"
LIGHT_FOLDER="Folder512x512@2x.png"
if [ $THEME == "system" ]; then
if [ "$(defaults read -g AppleInterfaceStyle)" == "Dark" ]; then
THEME_FOLDER_FILE=$DARK_FOLDER
else
THEME_FOLDER_FILE=$LIGHT_FOLDER
fi
else
if [ "$THEME" = "dark" ]; then
THEME_FOLDER_FILE=$DARK_FOLDER
else
THEME_FOLDER_FILE=$LIGHT_FOLDER
fi
fi
# extract blank folder from OS assets
ASSETS_LOCATION="/System/Library/PrivateFrameworks/IconFoundation.framework/Versions/A/Resources/Assets.car"
TMP=$TMPDIR/io.kmr.folderIcons
FOLDER_ICON="$TMP/$THEME_FOLDER_FILE"
# delete tmp if -f flag is set
if [[ $NO_CACHE ]]; then
rm -rf $TMP
fi
# extract blank folder
if test -f "$FOLDER_ICON"; then
echo "$(tput setaf 3)Blank folder already extracted, skipping...$(tput sgr0)"
else
echo "Extracting blank folder"
./bin/acextract -i $ASSETS_LOCATION -o $TMP > /dev/null
fi
# convert svgs
echo "Converting custom icons"
mogrify -density 2000 -resize x512 -background transparent -format png -path custom/ custom/*.svg
# build custom icon folders
echo "Building custom icons"
for file in custom/*.png; do
FILENAME=$(echo "$file" | cut -f 1 -d '.')
BASENAME="$(BASENAME "$FILENAME")"
convert $FOLDER_ICON \
\( -background transparent -size 512x512 -gravity center -geometry +0+40 $file -resize X340 -fill '#1ca1dd' -colorize 100% \) \
-compose over -composite "build/$BASENAME.png"
done
# build SF Pro icon folders
echo "Building symbol icons"
SYMBOLS=$(cat symbols.txt)
for ((i = 0; i < ${#SYMBOLS}; i++)); do
SYMBOL="${SYMBOLS:$i:1}"
convert $FOLDER_ICON \
\( -background transparent -fill '#1ca1dd' -font SF-Pro-Text-Regular -size 512x512 -size X340 -gravity center -geometry +0+40 label:$SYMBOL \) \
-compose over -composite build/$SYMBOL.png
done
# build .icns
echo "Building .icns files"
for file in build/*.png; do
FILENAME=$(echo "$file" | cut -f 1 -d '.')
mkdir "$FILENAME.iconset"
sips -z 16 16 "$FILENAME.png" --out "$FILENAME.iconset/icon_16x16.png" > /dev/null
sips -z 32 32 "$FILENAME.png" --out "$FILENAME.iconset/icon_16x16@2x.png" > /dev/null
sips -z 32 32 "$FILENAME.png" --out "$FILENAME.iconset/icon_32x32.png" > /dev/null
sips -z 64 64 "$FILENAME.png" --out "$FILENAME.iconset/icon_32x32@2x.png" > /dev/null
sips -z 128 128 "$FILENAME.png" --out "$FILENAME.iconset/icon_128x128.png" > /dev/null
sips -z 256 256 "$FILENAME.png" --out "$FILENAME.iconset/icon_128x128@2x.png" > /dev/null
sips -z 256 256 "$FILENAME.png" --out "$FILENAME.iconset/icon_256x256.png" > /dev/null
sips -z 512 512 "$FILENAME.png" --out "$FILENAME.iconset/icon_256x256@2x.png" > /dev/null
sips -z 512 512 "$FILENAME.png" --out "$FILENAME.iconset/icon_512x512.png" > /dev/null
cp "$FILENAME.png" "$FILENAME.iconset/icon_512x512@2x.png"
iconutil -c icns "$FILENAME.iconset"
rm -R "$FILENAME.iconset"
done
# cleanup build
rm -rf build/*.iconset build/*.png
echo "$(tput setaf 2)Build complete!$(tput sgr0) Icons are located in the $(tput setaf 4)build$(tput sgr0) folder."