0

I'm trying to create a service that will automatically apply a 'thumbnail.*' file of a folder to the folder as its icon. I'm using this answer here to build it, but with some modifications.

I've wrapped it in a for loop, but I'm having issue modifying the 'icon=' line to account for this.

for f in "$@"
do
# Sets an icon on file or directory
# Usage setIcon.sh iconimage.jpg /path/to/[file|folder]
set iconSource to do shell script "find $f -name thumbnail*"
set iconDestination to "$f"

icon="/tmp" & $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

rm $rsrc $icon
done
Community
  • 1
  • 1
Karric
  • 1,415
  • 2
  • 19
  • 32

1 Answers1

0

I believe that the problem is the &. The and is from AppleScript, not ShellScript so if you want to set the icon=, try this:

icon="/tmp"$iconSource

Or if $iconSource does not contain \ in its spaces then try this:

icon="/tmp$iconSource"

BTW Make sure $iconSource begins with /

Hope this helps! :)

YeaTheMans
  • 1,005
  • 8
  • 19