function main(){
var inputFolder = Folder.selectDialog("Select a folder of documents to process");
if(inputFolder == null) return;
var fileList = inputFolder.getFiles(/\.(jpg|tif|psd)$/i);
var startRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
for(var z in fileList){
open(fileList[z]);
var doc = app.activeDocument;
try{
var leftFile = new File(decodeURI(activeDocument.fullName.fsName).slice(0,-4) + "1.jpg");
}catch(e){alert("You need to save this document first");return;}
var rightFile = new File(decodeURI(activeDocument.fullName.fsName).slice(0,-4) + "2.jpg");
doc.flatten();
var LB = app.activeDocument.activeLayer.bounds;
var savedState = doc.activeHistoryState;
activeDocument.selection.select([[LB[0].value,LB[1].value], [(LB[2].value/2),LB[1].value], [(LB[2].value/2),LB[3].value], [LB[0].value, LB[3].value]], SelectionType.REPLACE, 0, false);
executeAction( charIDToTypeID( "Crop" ), undefined, DialogModes.NO );
SaveJPEG(leftFile,8);
doc.activeHistoryState = savedState;
activeDocument.selection.select([[LB[2].value/2,LB[1].value], [(LB[2].value),LB[1].value], [(LB[2].value),LB[3].value], [LB[2].value/2, LB[3].value]], SelectionType.REPLACE, 0, false);
executeAction( charIDToTypeID( "Crop" ), undefined, DialogModes.NO );
SaveJPEG(rightFile,8);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
app.preferences.rulerUnits = startRulerUnits;
}
}
main();
function SaveJPEG(saveFile, jpegQuality){
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality; //1-12
activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);
}