Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

allegrocm

macrumors member
Original poster
Mar 13, 2005
36
0
Ames, IA
Hello all,

I'm writing an art program for OSX, and I have a custom file format for saving its documents. I'd like to include an image preview as the icon for the documents. I found one way of doing this using the following sh script:

Code:
#!/bin/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
echo make icon from $1 for file $2

# Create icon from the iconSource
cp $iconSource $icon

# Add icon to image file, meaning use itself as the icon
sips -i $icon &&  echo "sips was successful"

# Take that icon and put it into a rsrc file
derezResult=-1
DeRez -only icns ${icon} | tee ${rsrc} && derezResult=0
echo $derezResult

# Apply the rsrc file to

SetFile -a C $iconDestination && echo "Setfile was successful"

if [ -f $iconDestination ]; then
    # Destination is a file
    Rez -append $rsrc -o $iconDestination && echo "append was successful"
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

But three of those tools are included with the developer tools (Rez, SetFile, DeRez), and I want to deploy this on systems that don't have the tools installed. Has anyone done this before? I have no problem saving out a png or jpg file of the image, but I'm not sure how to set that to be the icon for my document without using the above mentioned developer tools . Any advice would be greatly appreciated. Thank you!

Ken
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.