#target photoshop;
app.bringToFront();
main();
function main(){
var inputFolder = Folder("/R/Marketing/Images/Batch Done");
if(!inputFolder.exists) {
alert("Input folder does not exist");
return;
}
var outputFolder = Folder("/R/Marketing/Images/Batch To Go");
if(!outputFolder.exists) outputFolder.create();
var csv = File.openDialog("/R/Inventory/Test","CSV File:*.csv");
if(csv == null) return;
csv.open("r");
csv.encoding = "UTF-8";
var fileList = csv.read().split("\n");
csv.close();
//start at 1 to exclude header line. 0 if no header line
for(var a = 1;a<fileList.length;a++){
if(fileList[a].length < 3) continue;
var line = fileList[a].split(",");
var file = File(inputFolder + "/" + line[0].toString());
if(!file.exists) continue;
app.open(file);
var doc = activeDocument;
var res = doc.resolution;
//amend to suit.
doAction("Whole","Pair_Kit_Batch");
var outFile = File(outputFolder + "/" + line[1].toString() + ".jpg");
SaveJPEG(outFile, 8);
/////////////////////////////////////////////////////////////////////
//Set restore point
var savedState = app.activeDocument.activeHistoryState;
var outFile = File("/R/Marketing/Images/Batch Size1" + "/" + line[1].toString() + ".jpg");
//resize document to 1024 pixels wide keeping constrain
doc.resizeImage(new UnitValue(1024,'px'), undefined, res, ResampleMethod.BICUBIC);
SaveJPEG(outFile, 8);
//Restore back
doc.activeHistoryState = savedState;
/////////////////////////////////////////////////////////////////////
//Set restore point
var savedState = app.activeDocument.activeHistoryState;
var outFile = File("/R/Marketing/Images/Batch Size2" + "/" + line[1].toString() + ".jpg");
//resize document to 1000 pixels wide keeping constrain
doc.resizeImage(new UnitValue(1000,'px'), undefined, res, ResampleMethod.BICUBIC);
SaveJPEG(outFile, 8);
//Restore back
doc.activeHistoryState = savedState;
/////////////////////////////////////////////////////////////////////
//Set restore point
var savedState = app.activeDocument.activeHistoryState;
var outFile = File("/R/Marketing/Images/Batch Size3" + "/" + line[1].toString() + ".jpg");
//resize document to 800 pixels wide keeping constrain
doc.resizeImage(new UnitValue(800,'px'), undefined, res, ResampleMethod.BICUBIC);
SaveJPEG(outFile, 8);
//Restore back
doc.activeHistoryState = savedState;
/////////////////////////////////////////////////////////////////////
//Set restore point
var savedState = app.activeDocument.activeHistoryState;
var outFile = File("/R/Marketing/Images/Batch Size4" + "/" + line[1].toString() + ".jpg");
//resize document to 600 pixels wide keeping constrain
doc.resizeImage(new UnitValue(600,'px'), undefined, res, ResampleMethod.BICUBIC);
SaveJPEG(outFile, 8);
//Restore back
doc.activeHistoryState = savedState;
/////////////////////////////////////////////////////////////////////
//duplicate the block of code for as many times as required
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
};
function SaveJPEG(saveFile, jpegQuality){
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality;
activeDocument.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);
};