Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Closing a document within Javascript.

New Here ,
Aug 27, 2009 Aug 27, 2009

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.

TOPICS
Actions and scripting
17.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guru , Aug 27, 2009 Aug 27, 2009

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

Translate
Adobe
Advocate ,
Aug 27, 2009 Aug 27, 2009

Access the applications documents collection:

application.documents[0].close(false)

You can download the Javascript reference here: Adobe Photoshop CS3 JavaScript Scripting Reference

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Aug 27, 2009 Aug 27, 2009

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 27, 2009 Aug 27, 2009

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 27, 2009 Aug 27, 2009

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Aug 27, 2009 Aug 27, 2009

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);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 20, 2021 Jan 20, 2021
LATEST

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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines