Simple script makes Script Editor hang

Hi guys.

I’ve run into a weird problem while writing a simple AppleScript for Aperture. It works fine if I save it and run it from the script menu, but if I run it from Script Editor, all I get is a spinning beach-ball. How is this possible? This is the part of the script that makes it hang:

tell app “Aperture”
set sel_ to (get every image version of library 1)
set list_ to {}
repeat with i from 1 to (count sel_)
tell (item i of sel_)
if (get value of exif tag “CaptureYear”) is 2010 then
set end of list_ to (item i of sel_)
end if
end tell
end repeat
end tell

Does anybody have an idea why this works in the script menu but not in the editor?

Thanks,
Morten

Model: iMac 24" (early 2009)
Browser: Firefox 3.6.3
Operating System: Mac OS X (10.6)

I’m not sure, but I think maybe this line is the culprit:

tell (item i of sel_)

because you essentially say: item X of application Y

now, when you run the script from the script menu, application Y is Aperture.

but when you run the script from the script editor application Y is the AppleScirpt editor itself.

I’m not sure if this is the answer (I do not own Aperture to try it out), but there is a simple way to check: in the script editor, activate the Events pane, to see the literal interpretation of your commands. If you see any reference to AppleScirpt editor, you’ll know that’s the problem.

Hi LiMP.

Thanks but that doesn’t seem to be the problem. There are no references to Script Editor in the Event replies.
Also, I don’t see how I could be talking to Script Editor. The variable sel_ is a list containing unique paths to images in my Aperture Library. One item could look like this:

image version id "HBJtVZ9LRLuYaYfFLRFbbQ" of project id "OjEPHN6iSCO%DkdOsnlklA" of application "Aperture"

.

Maybe something’s wrong on my machine? This isn’t the only script that acts weirdly when run from the Editor. Another thing I’ve noticed when looking at my CPU history is that it’s much more erratic when running scripts from the editor. When run from the script menu, it never exceeds 50% on any core, but run from the editor, it’s always 100% on one core while the other is at 0% (they switch occasionally). I don’t have the faintest clue what’s going on, so I really hope someone out there can help me.

Thanks for your time and effort,
Morten

Model: iMac 24" (early 2009)
Browser: Firefox 3.6.3
Operating System: Mac OS X (10.6)