@raagav_9457 / @rajsriguide
Try this script:
/*
Batch Save Back Layer As JPEG to Sub-Folder.jsx
Stephen Marsh
v1.0 - 6th October 2025: Initial release
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-for-turning-off-all-layers-except-the-background-layer/td-p/15533386
*/
#target photoshop
(function () {
var inputFolder = Folder.selectDialog("Select an input folder containing PSD/PSB files");
if (inputFolder == null) return;
// Collect all PSD/PSB input files
var processFiles = inputFolder.getFiles(function (theFiles) {
return theFiles instanceof File && theFiles.name.match(/\.(psd|psb)$/i);
});
if (processFiles.length === 0) {
alert("No PSD or PSB files found in the selected folder.");
return;
}
// Create the output directory named "Input"
var outputFolder = new Folder(inputFolder.fsName + "/" + "Input"); // Change the name from "Input" as required
if (!outputFolder.exists) outputFolder.create();
app.togglePalettes();
// Create the scriptUI progress bar
var progressWin = new Window("palette", "Processing Files", undefined, { closeButton: false });
progressWin.orientation = "column";
progressWin.alignChildren = ["fill", "top"];
progressWin.margins = 15;
var infoText = progressWin.add("statictext", undefined, "Starting...");
infoText.characters = 50;
var progressBar = progressWin.add("progressbar", undefined, 0, processFiles.length);
progressBar.preferredSize = [400, 20];
var countText = progressWin.add("statictext", undefined, "0 of " + processFiles.length);
progressWin.show();
// Process the files
for (var i = 0; i < processFiles.length; i++) {
var currentFile = processFiles[i];
try {
// Progress bar processing
progressBar.value = i;
countText.text = (i + 1) + " of " + processFiles.length;
infoText.text = "Processing: " + decodeURI(currentFile.name);
progressWin.update();
var theDoc = app.open(currentFile);
var baseName = decodeURI(theDoc.name).replace(/\.[^\.]+$/, "");
// Layer visibility
backLayerVisible();
// JPEG save path
var jpegFile = new File(outputFolder.fsName + "/" + baseName + ".jpg");
// Set the JPEG save options
var jpegOptions = new JPEGSaveOptions();
jpegOptions.quality = 12;
jpegOptions.embedColorProfile = true;
jpegOptions.formatOptions = FormatOptions.STANDARDBASELINE;
// Save the JPEG copy
theDoc.saveAs(jpegFile, jpegOptions, true, Extension.LOWERCASE);
// Close the PSD/PSB without saving changes
theDoc.close(SaveOptions.DONOTSAVECHANGES);
} catch (e) {
alert("Error processing " + currentFile.name + ":\n" + e);
}
}
app.beep()
// End of progress bar processing
progressBar.value = processFiles.length;
infoText.text = "Done... All PSD/PSB files saved to JPEGs!";
countText.text = processFiles.length + " of " + processFiles.length;
progressWin.update();
$.sleep(1000);
app.bringToFront();
progressWin.close();
// End of script notification;
//alert("All PSD/PSB files saved to JPEGs!");
app.togglePalettes();
function backLayerVisible() {
if (!app.documents.length) return;
var doc = app.activeDocument;
var layers = doc.layers;
var total = layers.length;
if (total < 1) return;
for (var i = 0; i < total; i++) {
try {
// Turn off visibility for all top-level/root layers
layers[i].visible = false;
} catch (e) { }
}
try {
// Turn on the visibility of the back layer
layers[total - 1].visible = true;
} catch (e) { }
}
})();
- Copy the code text to the clipboard
- Open a new blank file in a plain-text editor (not in a word processor)
- Paste the code in
- Save as a plain text format file – .txt
- Rename the saved file extension from .txt to .jsx
- Install or browse to the .jsx file to run (see below)
https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html