I have not included checks for all potential problems (for example if you were to have two Layers names »base1« the resulting files would be overwritten without warning and numbers will only be considered to a length of 5 spaces).
But you could give it a try with some duplicate files.
// combine base with variation layers and save jpgs;
// 2012, use at your own risk;
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var docName = myDocument.name;
var basename = docName.match(/(.*)\.[^\.]+$/)[1];
var docPath = myDocument.path;
// jpg options;
var jpegOptions = new JPEGSaveOptions();
jpegOptions.quality = 9;
jpegOptions.embedColorProfile = true;
jpegOptions.matte = MatteType.NONE;
// get layers;
var theLayers = collectLayers(app.activeDocument, [[], []]);
var base = theLayers[0];
var variation = theLayers[1];
// create the combinations;
for (var m = 0; m < base.length; m++) {
base.visible = true;
for (var n = 0; n < variation.length; n++) {
variation.visible = true;
myDocument.saveAs((new File(docPath+"/image"+ base.name + variation.name +".jpg")), jpegOptions, true);
variation.visible = false;
}
base.visible = false;
};
};
////// function collect all layers //////
function collectLayers (theParent, allLayers) {
if (!allLayers) {var allLayers = new Array}
else {};
for (var m = theParent.layers.length - 1; m >= 0;m--) {
var theLayer = theParent.layers;
// apply the function to layersets;
if (theLayer.typename == "ArtLayer") {
if (theLayer.name.match(/^base\d{1,5}$/)) {allLayers[0].push(theLayer)};
if (theLayer.name.match(/^variation\d{1,5}$/)) {allLayers[1].push(theLayer)};
theLayer.visible = false
}
else {
allLayers = (collectLayers(theLayer, allLayers))
}
};
return allLayers
};