Last active
November 4, 2015 19:46
-
-
Save drew1kun/a6049c84386d978bf4a5 to your computer and use it in GitHub Desktop.
set an icon for file or folder in OS X
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
# Sets an icon on file or directory | |
# Usage setIcon.sh iconimage.jpg /path/to/[file|folder] | |
iconSource=$1 | |
iconDestination=$2 | |
icon=/tmp/`basename $iconSource` | |
rsrc=/tmp/icon.rsrc | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment