Hello!
I have a script I use to reduce the size of images in a folder which works great.
The problem is it slows down as it goes along. when it starts, it processes an image every 3-4 seconds, but it slows down the more pictures I am processing (1000’s)
Is there a step I am missing, or not closing, during this script?
set picFolder to choose folder
tell application "Finder" to set picList to get (name of files of (entire contents of (picFolder)))
tell application "Finder" to set newList to every file of (entire contents of (picFolder))
repeat with i from 1 to number of items in newList
set dupFile to (item i of newList) as Unicode text
tell application "Image Events"
activate
set newImage to (open alias dupFile)
set {image_width, image_height} to the dimensions of newImage
set imWidth to {image_width}
set imHeight to {image_height}
if imWidth > 700 then scale newImage to size 700
if imWidth < 700 then try
if imHeight > 700 then scale newImage to size 700
end try
save newImage
close newImage
end tell
end repeat
Thanks for your input!
higashijoe
AppleScript: 1.10.7
Operating System: Mac OS X (10.4)
Hi, higashijoe.
I haven’t been able to reproduce the slowing down effect with over 6000 files, so it might be due to something other than the script itself. However, there are a few efficiencies that would make the script faster.
local newList -- Otherwise the entire list could be saved back into the script file.
set picFolder to choose folder
tell application "Finder" -- Get the files as a list of alias to save coercing in the repeat.
try
set newList to (every file of entire contents of picFolder) as alias list
on error
set newList to (first file of entire contents of picFolder) as alias as list
end try
end tell
script -- If newList is long, it may be faster to reference it (o's nlist instead of just newList).
property nlist : newList
end script
set o to result
tell application "Image Events" to launch -- LAUNCH Image Events (don't activate it), just once.
repeat with i from 1 to (count newList)
set dupFile to (item i of o's nlist)
tell application "Image Events"
set newImage to (open dupFile)
set {imWidth, imHeight} to the dimensions of newImage
if (imWidth > 700) or (imHeight > 700) then
scale newImage to size 700
save newImage -- Save the image only if it's just been scaled.
end if
close newImage
end tell
end repeat
tell application "Image Events" to quit -- Quit Image Events afterwards.
Thank You Nigel!
I will give your suggestions a try.
I do know my scripts are usually not efficient, I am a novice at best.
Also thank you for including the explanations with your script, it will help me understand some of the differences.
Again, Thanks for the Time.
higashijoe