I've written a script, which copies the layer mask of the selected group to all layers in the group itself. Use Export Layers to Files script afterwards in order to export your layers to the desired file type (shipped with photoshop by default).
- Backup your photoshop file first
- Select the group/folder in the layer stack
- Select and run the script via File > Scripts > Browse
Copy-groupMask-to-groupLayers.jsx
#target Photoshop
// pass the layer name
function copy_mask(targetLayer) {
$.writeln(targetLayer);
var desc126 = new ActionDescriptor();
desc126.putClass( charIDToTypeID('Nw '), charIDToTypeID('Chnl') );
var ref111 = new ActionReference();
ref111.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('Msk ') );
ref111.putName( charIDToTypeID('Lyr '), targetLayer.toString() );
desc126.putReference( charIDToTypeID('At '), ref111 );
var ref112 = new ActionReference();
ref112.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('Msk ') );
ref112.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc126.putReference( charIDToTypeID('Usng'), ref112 );
desc126.putBoolean( charIDToTypeID('Dplc'), true );
executeAction( charIDToTypeID('Mk '), desc126, DialogModes.NO );
};
// get the document
var doc = app.activeDocument;
// get the selection
var group = doc.activeLayer;
// iterate through the layers and copy the mask
for (var i=0; i<group.layers.length; i++){
copy_mask(group.layers[i].name);
}