Created
February 22, 2017 12:12
-
-
Save nuada/260441da9ebc30cb98db9ecca88c07d9 to your computer and use it in GitHub Desktop.
Set custom icon of Mac OS X folder or file using resource forks.
This file contains 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
#!/bin/bash | |
# usage: set_icon.sh <some.icns or image_file> <folder or file path> | |
# Based on: http://www.amnoid.de/icns/makeicns.html | |
icon="$1" | |
target="$2" | |
if [[ -d "${target}" ]]; then | |
target_icon="${target}"/$'Icon\r' | |
else | |
target_icon="${target}" | |
fi | |
resource="/tmp/tmp$$.rsrc" | |
# Create resource fork | |
sips -i "${icon}" | |
DeRez -only icns "${icon}" > "${resource}" | |
# Remove resource from icon file | |
rm -f "${icon}/..namedfork/rsrc" | |
SetFile -a c "${icon}" | |
# Add resource to folder | |
Rez -append "${resource}" -o "${target_icon}" | |
SetFile -a C "${target}" | |
if [[ -d "${target}" ]]; then | |
chflags hidden "${target_icon}" | |
fi | |
rm "${resource}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, this did exactly what I needed!