// This script will flatten all open documents in Photoshop // ensure that there is at least one document open; if not, display error message if (documents.length == 0) { alert("There are no documents open."); } else { myTotalDocs = (documents.length - 1); for ( i = 0; i <= myTotalDocs; i++ ) //This loop will keep pages in order, with the last page on top { myDocument = app.documents[i]; app.activeDocument = myDocument; myDocument.flatten(); } }