Save for web not working in Photoshop CS4

I’m creating a script for Photoshop CS4 that crops from a document, pastes this into a new document and then saves it, using the export command. However, the script is not exporting the files; it does not fail or produce an error message, but it doesn’t save the files either. Can anyone figure out what I am doing wrong here?

tell application "Adobe Photoshop CS4"
	make new document with properties {height:100, width:100, name:"fred"}
	paste
	set docRef2 to the current document
	set docName2 to name of docRef2
	export docName2 in filename as save for web with options {quality:60, web format:JPEG}
	close current document saving no
end tell

The variable filename is set to something like “DISK:test files:ONE:TWO:TEST:COLOR:crops2:THINGY-LURID-24.jpg”

I know that answering my own question is one of the signs of madness :P, but the following change to the export line fixed the problem. Kind of annoying that nothing produced an error there, though…

export current document in file filename as save for web with options {quality:60, web format:JPEG}

Export is looking for a document reference, not a document name so that makes sense that the first version didn’t work. Weird that you didn’t get an error though.

I suspect that you could have also used your DocRef2 instead of “current document” and it would have worked.

export DocRef2 in file filename as save for web with options {quality:60, web format:JPEG}