I have a script running to my satisfaction when I set the script to make me choose a file.
What I really need is making the script loop through all files in a folder, checking them for a certain condition, and move the files into two different folders according to their condition (amount of pixels).
I have tried a lot of different ways the last few hours, but have not succeeded. I just can’t get the repeat syntax correct.
Can anyone give me a hint, pls?
set destinationFolder1 to "Path:to:folder1:"
set destinationFolder2 to "Path:to:folder2:"
set sourceFolder to "Path:to:sourcefolder:"
set pixToCheck to list folder sourceFolder without invisibles
set tmpFile to choose file
tell application "Image Events"
launch
set tmpImage to open tmpFile
set {tmpImageX, tmpImageY} to dimensions of tmpImage
set totalPixels to (tmpImageX * tmpImageY)
close tmpImage
if totalPixels > 14000000 then
tell application "Finder" to move file tmpFile to folder destinationFolder1
else
tell application "Finder" to move file tmpFile to folder destinationFolder2
end if
end tell
Regards Inge
Model: G5
Browser: Safari 525.20.1
Operating System: Mac OS X (10.5)
set destinationFolder1 to "Path:to:folder1:"
set destinationFolder2 to "Path:to:folder2:"
set sourceFolder to "Path:to:sourcefolder:"
tell application "Finder"
--set pixToCheck to list folder sourceFolder without invisibles
--set tmpFile to choose file
set allFiles to entire contents of sourceFolder
try
repeat with tmpFile in allFiles
tell application "Image Events"
--launch
set tmpImage to open tmpFile
set {tmpImageX, tmpImageY} to dimensions of tmpImage
set totalPixels to (tmpImageX * tmpImageY)
close tmpImage
end tell
if totalPixels > 14000000 then
move tmpFile to folder destinationFolder1
else
move tmpFile to folder destinationFolder2
end if
end repeat
end try
end tell
I assume that
a) sourceFolder contains only image files, otherwise you will have to add a check routine in order to handle other types of files
b) the Image Events part works as laid out in your code (didn’t test it at all)
I’d use:
set allfiles to every file in sourceFolder
If you use entire contents, it’s going to get all files in subfolders as well as the subfolders themselves. That may be what you want, but if you don’t, it’s just going to slow you down.