Photoshop script

Hi,

I need a script for photoshop automation.

I need to close, and save many open files (.jpg) after cropping&resizing them.
Photoshop has a “close all” command, but I have to do two operations for each file to save it as I need:
first, it asks if I want to save, and once I click on save the second dialogue is about the jpeg options, where I set the quality of image (a value between 1 and 12).

For the first part I got this from adobe forum:

#target photoshop
//Make Photoshop the formost Appplication
app.bringToFront();
// Requires at least one open document
while (app.documents.length > 0)
//Save all open windows
{activeDocument.close(SaveOptions.SAVECHANGES);
}

and works fine for the “save” part, but I again have to click on “ok” on the JPEGSaveOptions for each file.

I tried google and reading “javascript scripting reference photoshop cs3”
http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/photoshop/pdfs/photoshop_cs3_javascript_ref.pdf

But I don’t know how to implement the info in there, JPEGSaveOptions is on page 122

Will you please kindly give me the correct way of completing the existing code?

Thank you