SetFileIcon
version 0.1
Requires Mac OS X 10.4 or higher


HAMSoft Engineering allows free use of this code and/or software in its "as is" condition. HAMSoft Engineering disclaims any liability of any kind for any damages whatsoever resulting from the use of this code and/or software. If you find it useful please consider making a donation to help HAMSoft Engineering stay in business.

download the command line tool
download the source project

Use this command line tool to add an image file as the custom icon to a file or folder. It can also be used to remove the custom icon.

Usage: SetFileIcon
[-h] show the help text
[-image "imagePath"] path to the image to be used for the icon
[-file "filePath"] path to the file to set the icon
[-removeCustomIcon] removes the custom icon for the file

Examples:
1. This sets the image as the custom icon for the file:
SetFileIcon -image /path/to/image -file /path/to/file

2. This removes the custom icon from the file:
SetFileIcon -removeCustomIcon -file /path/to/file


Example usage of the tool with applescript:
Open this Script in your Editor

set exePath to (path to home folder as text) & "UnixBins:SetFileIcon"


set imagePath to (path to desktop folder as text) & "theImage.png"

set theFile to (path to desktop folder as text) & "Some File.txt"


do shell script quoted form of POSIX path of exePath & " -image " & quoted form of POSIX path of imagePath & " -file " & quoted form of POSIX path of theFile