Thanks for that @rob day! I'm trying to adapt it to meet my needs (see script bellow), but for some reason the open documents are not closing, even if there aren't preflight errors. Am I misssing anything?
for (var d=0; d<app.documents.length; d++)
{
var myDoc = app.documents.everyItem();
var wp = "Preflight"
var d = app.documents[d];
var tp = app.preflightProfiles.itemByName(wp)
if (tp.isValid) {
var pf = app.preflightProcesses.add(d, tp);
pf.waitForProcess();
pf.processResults;
if (pf.aggregatedResults[2] != "") {
alert("This document contains preflight errors.")
}
} else {
myDoc.close(SaveOptions.yes);
}
}
Maybe this?:
//your preflight profile name
var wp = "Preflight";
var tp = app.preflightProfiles.itemByName(wp);
//gets all of the open documents
var docs = app.documents.everyItem().getElements();
//make sure the preflight profile exists
if (!tp.isValid) {
alert("No Profile Named: " + wp)
}else{
var d, pf;
//loop thru the documents
for (var i = 0; i < docs.length; i++){
//the document to check
d = docs[i];
pf = app.preflightProcesses.add(d, tp);
pf.waitForProcess();
pf.processResults;
//if item 3 of the aggregated results is empty there are no errors
if (pf.aggregatedResults[2] == "") {
$.writeln(d.name + ": Contains no preflight errors—save and close.")
d.close(SaveOptions.yes);
}
};
}