Copy link to clipboard
Copied
I'm new here and new to javascripting in photoshop (though not new to javascript).
I've been trying to figure out how to do the equivalent of either the "File>Close" or the "File>Close All" menu item. Preferably programmatically specifying changes not be saved as the script will have saved what it wanted saved before closing.
I can't find a sample of this nor could I find other references to it in the forum. I'd appreciate any help that can be provided for this.
Thanks,
Steve Ellis.
1 Correct answer
I think what Mark posted must be Applescript. Here is how with Javascript
app.docRef.close(SaveOptions.SAVECHANGES); // save any changes - only works with files that have been opened or saved once
app.docRef.close(SaveOptions.DONOTSAVECHANGES);// doesn't save -works with any doc including new ones
Explore related tutorials & articles
Copy link to clipboard
Copied
Access the applications documents collection:
application.documents[0].close(false)
You can download the Javascript reference here: Adobe Photoshop CS3 JavaScript Scripting Reference
Copy link to clipboard
Copied
I think what Mark posted must be Applescript. Here is how with Javascript
app.docRef.close(SaveOptions.SAVECHANGES); // save any changes - only works with files that have been opened or saved once
app.docRef.close(SaveOptions.DONOTSAVECHANGES);// doesn't save -works with any doc including new ones
Copy link to clipboard
Copied
Thanks the second suggestion did the trick.
I figured out how to convert the first suggestion to javascript, but couldn't figure out what to convert the "true" to.
Thanks again.
Steve.
Copy link to clipboard
Copied
Sorry about that, my brain seems to be running a little buggy today. I neglected to look up the proper options for the close command (as well as typed out 'application.' instead of 'app.')
app.documents[0].close(SaveOptions.DONOTSAVECHANGES)
You can loop through the documents collection to close all opened documents.
Copy link to clipboard
Copied
Close the current document without saving:
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
Close all open documents without saving:
while (app.documents.length > 0) {
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
Copy link to clipboard
Copied
Not sure why, but this answer didn't work for me.
Instead, I used below:
app.activeDocument.close(SaveOptions.no);
(This was for indesign 2019)

