PDA

View Full Version : What's wrong with this script?


renaultssoftware
08-23-2010, 08:02 AM
Hi all.

The script below is supposed to go through a giant folder, with image files that are supposed to be 512x512. If not, they go to the trash.

Problem is, instead of opening in ImEv, the files open in Preview and that throws an error.

Any fixes?

tell application "Finder" to set x to every file of the folder (POSIX file "/Users/Slave/icons")
set u to {}
tell application "Image Events"
repeat with i in x
set y to open i
if the dimensions of y is not {512, 512} then
copy i to the end of u
end if
close y
end repeat
end tell
tell application "Finder" to delete u

Thanks!

Red_Menace
08-23-2010, 10:27 AM
Image Events (along with quite a few other applications) doesn't like the Finder references, so its open command is failing. When the open command fails, it passes the command up the chain for something else that understands it, which results in the file opening with the default application.

Try using an alias list, for example
tell application "Finder" to set x to (every file of the folder (POSIX file "/Users/Slave/icons")) as alias list

renaultssoftware
08-23-2010, 01:57 PM
Oh, I keep forgetting that one thing. It's (i as alias) or something. Fixed! lol :D