A script to batch convert images between formats

Oct 08, '04 03:16:00PM

Contributed by: robspychala

To recursively batch convert images from one format to another using AppleScript Image Events, create the following shell script:

#!/bin/bash
# A simple bash script that uses AppleScript and ImageEvents to
# recursively transverse a directory structure and convert 
# between image formats

if [ ${#} -ne 3 ]
then
  echo "Image conversion script using Apple Image Events."
  echo ""
  echo "    Usage: ${0} [DIR] [file ext] [jpeg2|tiff|jpeg|pict|bmp|psd|png]"
  echo ""
  exit;
fi
if [ "${1}" != "-convert" ]
then
  echo ""
  echo "starting in: $1"
  echo "getting all the $2 files to convert to $3"
  find $1 -name "*.$2" -exec ./$0 -convert {} $3 ;
  exit 1
fi

jpg_file="$2"
pict_file="${2%%.*}.${3}"

if [ -e "${pict_file}" ]
then
  rm $pict_file
  echo "deleted old pict"
fi

echo "converting ${jpg_file} to ${pict_file}"
osascript
Remember to make the script executable.

[robg adds: I haven't tested this one, and as with anything that modifies a file, make sure you have a backup of whatever you're feeding to the script, just in case...]

Comments (13)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20041004121628900