Skip to content

Instantly share code, notes, and snippets.

@naotone
Last active August 29, 2015 14:08
Show Gist options
  • Save naotone/e32861e33312089e8d45 to your computer and use it in GitHub Desktop.
Save naotone/e32861e33312089e8d45 to your computer and use it in GitHub Desktop.
Auto set thumbnail icons to .mov.
#!/bin/sh
# Based on http://stackoverflow.com/questions/8371790/how-to-set-icon-on-file-or-directory-using-cli-on-os-x
# Usage
# cd path/to/moviesAndImagesDir/
# thisFileName.sh ./ [jpg|png]
dirPath=$1
thumbExt=$2
IFS=$'\n'
for file in ${dirPath}*.mov
do
movName=${file##*/}
movName=${movName%.*}
iconExt="."${thumbExt}
iconSource=$movName$iconExt
movExt=".mov"
movNameExt=$movName$movExt
# echo ${movName}
# echo ${iconSource}
icon=/tmp/`basename $iconSource`
rsrc=/tmp/${movName}.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 $movNameExt
if [ -f $movNameExt ]; then
# Destination is a file
Rez -append $rsrc -o $movNameExt
elif [ -d $movNameExt ]; then
# Destination is a directory
# Create the magical Icon\r file
touch $movNameExt/$'Icon\r'
Rez -append $rsrc -o $movNameExt/Icon?
SetFile -a V $movNameExt/Icon?
fi
done
# # Sometimes Finder needs to be reactivated
# #osascript -e 'tell application "Finder" to quit'
# #osascript -e 'delay 2'
# #osascript -e 'tell application "Finder" to activate'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment