Skip to content

Instantly share code, notes, and snippets.

@joncardasis
Created May 3, 2017 16:00
Show Gist options
  • Save joncardasis/63b2558739ab1384d93139616cbd0f1f to your computer and use it in GitHub Desktop.
Save joncardasis/63b2558739ab1384d93139616cbd0f1f to your computer and use it in GitHub Desktop.
Set the Finder icon of a single file in macOS
#!/bin/sh
# Sets an icon for a file
# Parameters:
# $1 icon_source - file path to the icon soruce (a .icns file)
# $2 file_path - file path the the destination file to change the icon of
icon_source=$1
file_path=$2
generated_icon=".icon.rsrc"
# Create rsrc file
DeRez -only icns $icon_source > $generated_icon
# Apply rsrc file
SetFile -a C "$file_path"
Rez -append $generated_icon -o "$file_path"
# Removed generated file
rm $generated_icon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment