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

Save All and Close Script, it runs but there needs to be some tweaks

Community Beginner ,
May 04, 2023 May 04, 2023

Copy link to clipboard

Copied

So, I've spliced together some of my scripts where I would love to save all open documents and close them without any dialogues. 

/* Start Saved Document Error Check - Part A: Try */
savedDoc();

function savedDoc() {
    try {
        app.activeDocument.path;
        /* Finish Saved Document Error Check - Part A: Try */

        /* Main Code Start */
        for (var i = 0; i < app.documents.length; i++) {
            app.activeDocument = app.documents[i];

        }
            
            // File Saving Code
            var idsave = charIDToTypeID( "save" );
            var desc4783 = new ActionDescriptor();
            var idIn = charIDToTypeID( "In  " );
            var idsaveStage = stringIDToTypeID( "saveStage" );
            var idsaveStageType = stringIDToTypeID( "saveStageType" );
            var idsaveBegin = stringIDToTypeID( "saveBegin" );
            desc4783.putEnumerated( idsaveStage, idsaveStageType, idsaveBegin );
            var idDocI = charIDToTypeID( "DocI" );
            desc4783.putInteger( idDocI, 1194 );
        executeAction( idsave, desc4783, DialogModes.NO );

        // Close All Open Docs
    
        while (app.documents.length) {
        app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        }
        // alert("All open documents closed!");
    

        /* Main Code Finish */
    }

    /* Start Saved Document Error Check - Part B: Catch */
    catch (err) {
        alert("One or more previously saved documents must be open before running this script!");
    }
}
/* Finish Saved Document Error Check - Part B: Catch */

 

I found this script in another post here.
But I've modified it to be a save command but the problem I've found, that the script will run but it'll save only one document that you're viewing when running the script and close all. Is there something missing in the code here? 

TOPICS
Actions and scripting , macOS

Views

555

Translate

Translate

Report

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
Adobe
Community Expert ,
May 04, 2023 May 04, 2023

Copy link to clipboard

Copied

In your loop statement, I would just save then cose the document. Put the number of open files in a variable first, then put that variable in your loop rather than the app doc length, so the script saves then closes the file. Then get rid of the while loop to close.

 

#target photoshop

/* Start Saved Document Error Check - Part A: Try */
savedDoc();

function savedDoc() {
    try {
        app.activeDocument.path;
        /* Finish Saved Document Error Check - Part A: Try */

        /* Main Code Start */
        var docNumber = app.documents.length
        for (var i = 0; i < docNumber; i++) {            
     
       // File Saving Code
            var idsave = charIDToTypeID( "save" );
            var desc4783 = new ActionDescriptor();
            var idIn = charIDToTypeID( "In  " );
            var idsaveStage = stringIDToTypeID( "saveStage" );
            var idsaveStageType = stringIDToTypeID( "saveStageType" );
            var idsaveBegin = stringIDToTypeID( "saveBegin" );
            desc4783.putEnumerated( idsaveStage, idsaveStageType, idsaveBegin );
            var idDocI = charIDToTypeID( "DocI" );
            desc4783.putInteger( idDocI, 1194 );
        executeAction( idsave, desc4783, DialogModes.NO );

        app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        
        // alert("All open documents closed!");
         }  

        /* Main Code Finish */
    }

    /* Start Saved Document Error Check - Part B: Catch */
   catch (err) {
        alert("One or more previously saved documents must be open before running this script!");
   }
}
/* Finish Saved Document Error Check - Part B: Catch */

 

 

Votes

Translate

Translate

Report

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
People's Champ ,
May 04, 2023 May 04, 2023

Copy link to clipboard

Copied

LATEST
var doc = [];
for (var i = 0; i < app.documents.length; i++) doc[i] = app.documents[i];

for (var i = 0; i < doc.length; i++) doc[i].close(SaveOptions.SAVECHANGES);

Votes

Translate

Translate

Report

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