I'm having a problem with an applescript that is exiting with a "variable ... is not defined" message.
Two variables are included in a top level "global" statement and are "set" in a handler. The handler is called from within a "tell" block and the code in the first variable runs. Then code in the second variable runs but after it has run the script exits complaining that the second variable is undefined. Besides wanting to fix this I would like to understand what is different between the two variables (ie why the first is defined and the second isn't). And also why the code in the second variable runs and then the script complains about it being undefined. It seems like the code wouldn't be run at all if the variable referencing it were undefined.
Here's the handler. imgGT1000 is the variable that works, imgHalfSize is the one that is "undefined". I've been testing with a horizontal image (2106 pixels wide) so the "else" section is the one that runs.
on imgResize() tell application "Adobe Photoshop CS" if (docHeight > docWidth) then set imgGT1000 to ((docHeight > 1000)) set imgHalfSize to resize image current document height (docHeight * 0.5) else set imgGT1000 to ((docWidth > 1000)) set imgHalfSize to resize image current document width (docWidth * 0.5) end if end tell end imgResize
The handler call and the variables are used in a photoshop tell block and occur in this order:
my imgResize() repeat while imgGT1000 imgHalfSize
The end of the "Event Log" shows that the image is resized then variable imgHalfSize is found to be undefined: resize image current document width 1053.0 current application "The variable imgHalfSize is not defined." |