After using the last post’s script a bit, I figured I should add some notification of what’s going on. I added a simple Growl Notification to Hazel before the script starts, and then setup GrowlNotify to report which file I should use, and the percentage of size savings.

New script follows:

#!/bin/tcsh
echo Converting "$1" to "${1:r}.jpg"
@ InitSize = -Z "$1"
/opt/local/bin/optipng -o7 "$1"
@ PNGSize = -Z "$1"
/opt/local/bin/convert "$1" "${1:r}.jpg"
/opt/local/bin/jhead -purejpg "${1:r}.jpg"
@ JPGSize = -Z "${1:r}.jpg"
if ( $PNGSize > $JPGSize ) then
set Perc = `echo $JPGSize \* 100 / $PNGSize | bc -l | cut -c 1-5`
/usr/local/bin/growlnotify -m "Shrunk $1 to ${1:r}.jpg, ${Perc}%" PNGtoJPG
rm "$1"
else
set Perc = `echo $InitSize \* 100 / $PNGSize | bc -l | cut -c 1-5`
/usr/local/bin/growlnotify -m "Shrunk $1, ${Perc}%" PNGtoJPG
rm "${1:r}.jpg"
endif