Image Events quirky behavior

As many of you know, there have been a number recent threads over the last few months concerning the oddites associated with trying to script the Image Events application. Most of the time, it will work if you tell Image Events to open the target file as an alias. Here is something else I have found, and it is making me mad:


set main_path to path to desktop as Unicode text
set a to choose file
set nfn to text returned of (display dialog "Enter new name:" default answer "")
set new_file to main_path & nfn & ".jpg"
tell application "Image Events"
	set b to open (a as alias)
	scale b by factor 0.1
	save b in new_file
	close b --Tried to do [save b closing in new_file] but it freaked and would not save.
end tell

This baby works fine as long as it is run in Script Editor with the Event Log pane highlighted. If you run it otherwise, or if you save it as an application, you get the fun error:

variable b not defined

This is truly exasperating, as I would like to use this to make a nifty HTML catalog of a bunch of non iPhoto disks of images I have collected. I have followed some of the recommendations of other similar threads, and investigated third party applications, but I would rather go straight to SIPS unless someone else has solved this strangeness.

I am running 10.4.3, Developer Tools installed

casdvm

Ok, I found a solution moments after my last post, ironically located in a thread I had started a few months ago. Nigel Garvey posted a script that made two key changes:

tell application "Image Events"
	close images

Closes any images inadvertently left open, and:

save b in file new_file

Tell Image Events specifically to save IN A FILE and give the filename/location in a variable.

So, this script works just fine, either as an app, or with the Results pane highlighted:

set main_path to path to desktop as Unicode text
set a to choose file
set nfn to text returned of (display dialog "Enter new name:" default answer "")
set new_file to main_path & nfn & ".jpg"
tell application "Image Events"
	close images
	set b to open (a as alias)
	scale b by factor 0.1
	save b in file new_file
	close b --Tried to do [save b closing in new_file] but it freaked and would not save.
end tell

Sorry to take up space, but really, I have not had time to mess with this stuff for the last few months, and I neglected to carefully read all the previous posts first

casdvm