Skip to content

Commit 853c635

Browse files
committed
Add script to set icons on folders or files, including .pkg
1 parent 36e722a commit 853c635

File tree

1 file changed

+39
-0
lines changed
  • src/com/inet/gradle/setup/dmg/template/dmgbuild

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/sh
2+
# Sets an icon on file or directory
3+
# Usage setIcon.sh iconimage.jpg /path/to/[file|folder]
4+
# see https://stackoverflow.com/questions/8371790/how-to-set-icon-on-file-or-directory-using-cli-on-os-x
5+
6+
iconSource=$1
7+
iconDestination=$2
8+
icon=/tmp/`basename "$iconSource"`
9+
rsrc=/tmp/icon.rsrc
10+
11+
# Create icon from the iconSource
12+
cp "$iconSource" "$icon"
13+
14+
# Add icon to image file, meaning use itself as the icon
15+
sips -i "$icon"
16+
17+
# Take that icon and put it into a rsrc file
18+
DeRez -only icns "$icon" > "$rsrc"
19+
20+
# Apply the rsrc file to
21+
SetFile -a C "$iconDestination"
22+
23+
if [ -f "$iconDestination" ]; then
24+
# Destination is a file
25+
Rez -append "$rsrc" -o "$iconDestination"
26+
elif [ -d "$iconDestination" ]; then
27+
# Destination is a directory
28+
# Create the magical Icon\r file
29+
touch "$iconDestination/$'Icon\r'"
30+
Rez -append "$rsrc" -o "$iconDestination/Icon?"
31+
SetFile -a V "$iconDestination/Icon?"
32+
fi
33+
34+
# Sometimes Finder needs to be reactivated
35+
#osascript -e 'tell application "Finder" to quit'
36+
#osascript -e 'delay 2'
37+
#osascript -e 'tell application "Finder" to activate'
38+
39+
rm "$rsrc" "$icon"

0 commit comments

Comments
 (0)