I have the script partially working.
It saves all the open psd as jpg into into a separate directory and it close some of the open files not all.
The directory has five files. The script saves only three files,
What am I doing wrong?
#target photoshop
if (app.documents.length > 0) {
//flatten the active document
app.activeDocument.flatten();
//jpeg options
var myJPEGOptions = new JPEGSaveOptions();
myJPEGOptions.embedColorProfile = true;
myJPEGOptions.formatOptions = FormatOptions.STANDARDBASELINE;
myJPEGOptions.matte = MatteType.WHITE;
myJPEGOptions.quality = 12;
myJPEGOptions.scans = 3;
// get documents;
var docs = app.documents;
for (var m = 0; m < app.documents.length; m++) {
app.activeDocument = docs[m];
try {
//save file to folder
var myFile = new File(("~/Desktop/forum-test") + "/" + activeDocument.name);
app.activeDocument.saveAs(myFile, myJPEGOptions, true);
//close the document
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
catch (e) {
alert ("Error the script did not execute");
}
}
}
2
Answers
I think this two lines are wrong:
and
Shouldn’t you be using
app.activeDocument
instead ofactiveDocument
? What isactiveDocument
anyway?The
app.documents
collection is dynamic so when you close a document this collection is changed accordingly.Because you are closing your document inside a for loop where you compare an incrementing index against
app.documents.length
you are not processing all files (asapp.documents.length
decreases by one each time the loop is processed).Try a while loop instead: