#target photoshop;
main();
function main(){
inputFolder = Folder.selectDialog("Please select the folder with Files to process");
if(inputFolder == null) return;
var newPath = Folder(decodeURI(inputFolder +"/Stacked"));
if(!newPath.exists) newPath.create();
var fileList = inputFolder.getFiles(/\.(jpg)$/i);
var files = new Array();
while(fileList.length >2){
for(var a =0;a<3;a++){files.push(fileList.shift());}
var Name = decodeURI(files[0].name).replace(/\.[^\.]+$/, '');
stackFiles(files);
var saveFile = File(newPath + "/" + Name + "-Stack.psd");
SavePSD(saveFile);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
files=[];
}
};
function stackFiles(files){
var loadLayersFromScript = true;
$.evalFile(app.path + "/" + localize("$$$/ScriptingSupport/InstalledScripts=Presets/Scripts") + "/Load Files into Stack.jsx");
loadLayers.intoStack(files);
};
function SavePSD(saveFile){
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true;
activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
};