Copy link to clipboard
Copied
Hello!
I often have this:
I open several files at once and create layers in them. Then I need to flatten image in all open documents.
Is it possible to make it at once and to write it down in the script?
Sincerely,
Niyetkhan
1 Correct answer
This version will just flatten all open docs, without saving or closing (probably closer to what you were looking for than the previous script).
/*
Use this script at your own risk!
Flatten image for all open documents
https://community.adobe.com/t5/photoshop-ecosystem-discussions/flatten-image-for-all-open-documents/m-p/12617518#M610710
Flatten All Open Files.jsx
Stephen Marsh, v1.0 - 26 December 2021
*/
#target photoshop
// CHECK FOR OPEN DOCS
if (app.documents.length) {
// OPTIONAL
...
Explore related tutorials & articles
Copy link to clipboard
Copied
I understand your workflow, however such as script is fraught with danger, so file under the cateogory of "be careful what you wish for"! This script will flatten, save and close all open docs, use at your own risk!
/*
Use this script at your own risk!
This script assumes that all open images have been previously saved from Photoshop.
Flatten image for all open documents
https://community.adobe.com/t5/photoshop-ecosystem-discussions/flatten-image-for-all-open-documents/m-p/12617518#M610710
Flatten Save & Close All Open Files.jsx
Stephen Marsh, v1.0 - 26 December 2021
*/
#target photoshop
// CHECK FOR OPEN DOCS
if (app.documents.length) {
// OPTIONAL CONFIRMATION
if (!confirm("Are you really sure that you wish to flatten, save and close all open docs?", false)) {
//throw alert("Script cancelled!");
throw null;
}
// LOOP OVER OPEN FILES
while (app.documents.length > 0) {
app.activeDocument.flatten();
app.activeDocument.close(SaveOptions.SAVECHANGES);
}
// END OF SCRIPT NOTIFICATION
app.beep();
// ALERT IF NO DOCS OPEN
} else {
alert('You must have a document open!');
}
https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html
Copy link to clipboard
Copied
This version will just flatten all open docs, without saving or closing (probably closer to what you were looking for than the previous script).
/*
Use this script at your own risk!
Flatten image for all open documents
https://community.adobe.com/t5/photoshop-ecosystem-discussions/flatten-image-for-all-open-documents/m-p/12617518#M610710
Flatten All Open Files.jsx
Stephen Marsh, v1.0 - 26 December 2021
*/
#target photoshop
// CHECK FOR OPEN DOCS
if (app.documents.length) {
// OPTIONAL CONFIRMATION
if (!confirm("Are you really sure that you wish to flatten all open docs?", false)) {
//throw alert("Script cancelled!");
throw null;
}
// SET THE CURRENT DOC AS ORIGINAL DOC
var actDoc = app.activeDocument;
// LOOP OVER OPEN FILES
for (var i = 0; i < app.documents.length; i++) {
app.activeDocument = app.documents[i];
app.activeDocument.flatten();
}
// RETURN TO THE ORIGINAL DOC
app.activeDocument = actDoc;
// END OF SCRIPT NOTIFICATION
app.beep();
alert("All open doc's layers have been flattened!")
// ALERT IF NO DOCS OPEN
} else {
alert('You must have a document open!');
}
Copy link to clipboard
Copied
Adobe installs a Photoshop Script that will do the for you in Photoshop. Photoshop menu File>Scripts>Image Processor... You can at the same time save layered versions of your open documents by saving a PSD or Tiff version as well as a flat jpeg file.

