Here is a custom script for the task:
/*
Save JPEG Files from Patterns Group.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/automate-an-export-with-some-visible-layers/m-p/13572441
Based on
https://community.adobe.com/t5/photoshop-ecosystem-discussions/way-to-turn-on-the-next-hidden-layer-to-automate-comps/td-p/13450230
v1.0 21st March 2022, Stephen Marsh
Info: Saves all visible layers with only one layer visible from the 'patterns' group as a JPEG file. The file will be named after the 'patterns' layer name, duplicate layers will have a unique layer name to avoid overwriting existing files.
*/
#target photoshop
if (documents.length) {
function main() {
// Select the "patterns" group
activeDocument.activeLayer = activeDocument.layerSets["patterns"];
// Check for active layer group and case sensitive name of "patterns"
if (activeDocument.activeLayer.typename === "LayerSet" && activeDocument.activeLayer.name === "patterns") {
// Set the output folder
var docSavePath = Folder.selectDialog("Select the JPEG save folder:");
// Setup the script timer
var timeDiff = {
setStartTime: function () {
d = new Date();
time = d.getTime();
},
getDiff: function () {
d = new Date();
t = d.getTime() - time;
time = d.getTime();
return t;
}
};
timeDiff.setStartTime();
// All child layers in the parent group should be hidden at the start of the script
for (var i = 0; i < activeDocument.activeLayer.layers.length; i++) {
activeDocument.activeLayer.layers[i].visible = false;
}
// Set the doc variable
var doc = app.activeDocument;
// Set the file processing counter at zero
var counter = 0;
// Loop over the contents of the selected layer group and save JPEGs
for (var i = 0; i < activeDocument.activeLayer.layers.length; i++) {
var layerName = activeDocument.activeLayer.layers[i].name;
activeDocument.activeLayer.layers[i].visible = true;
var jpgSave = new File(docSavePath + "/" + layerName + ".jpg");
// Check for existing file and make the filename unique
if (jpgSave.exists) {
jpgSave = new File(docSavePath + "/" + layerName + " - Duplicate " + counter + ".jpg");
}
// Setup the save options
var jpgOptns = new JPEGSaveOptions();
jpgOptns.formatOptions = FormatOptions.STANDARDBASELINE;
jpgOptns.embedColorProfile = true;
jpgOptns.matte = MatteType.NONE;
jpgOptns.quality = 10;
// Save the JPEG
doc.saveAs(jpgSave, jpgOptns, true, Extension.LOWERCASE);
// Reset the layer visibility
activeDocument.activeLayer.layers[i].visible = false;
// Increment the file processing counter
counter++;
}
// Select the top layer in the 'patterns' group
activeDocument.activeLayer = app.activeDocument.layerSets["patterns"].layers[0];
// End of script notification
alert(counter + " JPEG files created!" + "\n" + "(" + timeDiff.getDiff() / 1000 + " seconds)");
} else {
alert("The selected layer isn't a layer group or isn't named 'patterns'!");
}
}
activeDocument.suspendHistory("Save JPEG Files from Patterns Group...", "main()");
} else {
alert("A document must be open to run this script!");
}