#!/usr/bin/perl -w
use strict;
my $scaleCommand = "/usr/bin/osascript /Users/<user>/Documents/AppleScripts/scaleImage.scpt";
my $imageFile;
my $path = shift;
my @imageFiles = `ls $path | grep JPG`;
my $imageSmall = "_sm";
my $imageSuffix = ".JPG";
my $fullPath = `pwd`;
chomp $fullPath;
foreach $imageFile (@imageFiles) {
if($imageFile =~ m/$imageSuffix$/) {
chomp $imageFile;
my($file,$suffix) = split('\.', $imageFile);
my $newFile = $file . $imageSmall . $imageSuffix;
`cp $imageFile $newFile`;
my $pathToImage = $fullPath . "/" . $newFile;
print "Scaling new image file: " . $pathToImage . "\n";
`$scaleCommand $pathToImage`;
}
}