Reputation: 946
I'm trying to make a photoshop script that closes all documents without saving except for the first document. The first document will be a psd/psdc, the rest will be images
Currently I have the below code, this closes all documents
while (app.documents.length > 0) {
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
I've tried modifying it the same way I've done with a previous script, but it closes random documents, and not even all of them, it can leave 5-6 documents open
for (var i = 1; i < app.documents.length; i++) {
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
Can anyone point me in the right direction
Upvotes: 1
Views: 533
Reputation: 2269
Just use the inverted loop (so the docs are closed from the last to the first) and address them by the reference from the documents
array, not by active document:
for (var i = documents.length - 1; i >= 1; i--) {
documents[i].close(SaveOptions.DONOTSAVECHANGES)
}
Upvotes: 2