applescript and Image Events
The following script works correctly:
property openTypes : {"PDF", "com.adobe.pdf", "BMP", "com.microsoft.bmp", "JPEG", "JPEG2", "jpg", "public.jpeg", "PICT", "com.apple.pict", "PNG", "public.png", "PSD", "com.adobe.photoshop-image", "TIFF", "public.tiff"}
global eventsFolder, ProcessedfolderName, events_Folder
on runConversion(theItems)
activate "Finder"
set saveFolder to choose folder with prompt "Save resized pictures where?" without multiple selections allowed and invisibles
tell application "Image Events"
launch
set newWidth to 120
if (count items of theItems) is greater than 0 then
repeat with anItem in theItems
set theName to the name of anItem
tell application "Finder" to set myNewFileName to (saveFolder as string) & "tmb_" & theName
set imageFile to (open anItem)
scale imageFile to size newWidth
save imageFile as PNG in file myNewFileName
close imageFile
end repeat
else
display dialog "Nothing to convert."
end if
end tell
end runConversion
mount volume someVolume
set root_Folder to root_Folder as alias
set events_Folder to events_Folder as alias
set theStr to (current date) as string
set d to date theStr
set ProcessedfolderName to ((month of d as integer) & "_" & day of d) as text
tell application "Finder"
set events_Folder to events_Folder as alias
set ProcessedfolderName to ((month of d as integer) & "_" & day of d) as text
set new_FileFolder to make new folder at events_Folder with properties {name:ProcessedfolderName}
move (every file of events_Folder whose name ends with ".png") to new_FileFolder
set oldFiles to every file of events_Folder
set thecount to number of items of oldFiles
end tell
set theFiles to choose file with prompt "Choose the files" of type openTypes with multiple selections allowed without invisibles
runConversion(theFiles)
activate
BUT if I modify it to the following, it gets hung up on "scale imageFile to size newWidth"
error "The variable imageFile is not defined." number -2753 from "imageFile"
Maybe it has something to do with the line
'set theFiles to choose file with prompt "Choose the files" of type openTypes with multiple selections allowed without invisibles'
which is not in the broken script.
The broken script is as follows:
property openTypes : {"PDF", "com.adobe.pdf", "BMP", "com.microsoft.bmp", "JPEG", "JPEG2", "jpg", "public.jpeg", "PICT", "com.apple.pict", "PNG", "public.png", "PSD", "com.adobe.photoshop-image", "TIFF", "public.tiff"}
global eventsFolder, ProcessedfolderName, new_FileFolder, imageFile
on runConversion(theItems)
activate "Finder"
set saveFolder to new_FileFolder
set theItems to every file of the saveFolder
tell application "Image Events"
launch
set newWidth to 120
if (count items of theItems) is greater than 0 then
repeat with anItem in theItems
set theName to the name of anItem
tell application "Finder" to set myNewFileName to (saveFolder as string) & "tmb_" & theName
set imageFile to (open anItem)
scale imageFile to size newWidth
save imageFile as PNG in file myNewFileName
close imageFile
end repeat
else
display dialog "Nothing to convert."
end if
end tell
end runConversion
mount volume mountVolume
set root_Folder to rootFolder as alias
set events_Folder to events_Foler as alias
set theStr to (current date) as string
set d to date theStr
set ProcessedfolderName to ((month of d as integer) & "_" & day of d) as text
tell application "Finder"
set ProcessedfolderName to ((month of d as integer) & "_" & day of d) as text
set new_FileFolder to make new folder at events_Folder with properties {name:ProcessedfolderName}
move (every file of events_Folder whose name ends with ".png") to new_FileFolder
set oldFiles to every file of events_Folder
set thecount to number of items of oldFiles
end tell
set theFiles to every file of new_FileFolder
runConversion(theFiles)
activate
Mac Pro, Mac OS X (10.6.4)