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?
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 */
Copy link to clipboard
Copied
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);