-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsetfileicon.sh
executable file
·41 lines (33 loc) · 1.19 KB
/
setfileicon.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
#!/bin/sh
# Sets an icon on file or directory
# Usage setfileicon.sh iconimage.jpg /path/to/[file|folder]
# originally from https://stackoverflow.com/questions/8371790/how-to-set-icon-on-file-or-directory-using-cli-on-os-x
# modified to allow iconDestination to contain spaces
iconSource=$1
iconDestination=$2
icon=/tmp/`basename $iconSource`
rsrc=/tmp/icon.rsrc
echo "Setting icon on $iconDestination to $iconSource"
# Create icon from the iconSource
cp $iconSource $icon
# Add icon to image file, meaning use itself as the icon
sips -i $icon
# Take that icon and put it into a rsrc file
DeRez -only icns $icon > $rsrc
# Apply the rsrc file to
SetFile -a C "$iconDestination"
if [ -f "$iconDestination" ]; then
# Destination is a file
Rez -append $rsrc -o "$iconDestination"
elif [ -d "$iconDestination" ]; then
# Destination is a directory
# Create the magical Icon\r file
touch "$iconDestination"/$'Icon\r'
Rez -append $rsrc -o "$iconDestination"/Icon?
SetFile -a V "$iconDestination"/Icon?
fi
# Sometimes Finder needs to be reactivated
#osascript -e 'tell application "Finder" to quit'
#osascript -e 'delay 2'
#osascript -e 'tell application "Finder" to activate'
rm $rsrc $icon