Please try this:
// 2014 , use it at your own risk;
#target Photoshop
app.bringToFront;
var inFolder = Folder.selectDialog("Please select folder to process");
if(inFolder != null){
var fileList = retrieveFiles (inFolder, []);
var outfolder = new Folder(decodeURI(inFolder) + "/Edited");
if (outfolder.exists == false) outfolder.create();
for(var a = 0 ;a < fileList.length; a++){
if(fileList[a] instanceof File){
var doc= open(fileList[a]);
doc.flatten();
var docname = fileList[a].name.slice(0,-4);
CropStraighten();
doc.close(SaveOptions.DONOTSAVECHANGES);
var count = 1;
while(app.documents.length){
var saveFile = new File(decodeURI(outfolder) + "/" + docname +"#"+ zeroPad(count,3) + ".tif");
saveCopyAsTif(app.activeDocument, saveFile);
activeDocument.close(SaveOptions.DONOTSAVECHANGES) ;
count++;
}
}
}
};
//////
function CropStraighten() {
executeAction( stringIDToTypeID('CropPhotosAuto0001'), undefined, DialogModes.NO );
};
////// get from subfolders //////
function retrieveFiles (theFolder, theFiles) {
if (!theFiles) {var theFiles = []};
var theContent = theFolder.getFiles();
for (var n = 0; n < theContent.length; n++) {
var theObject = theContent[n];
if (theObject.constructor.name == "Folder") {
theFiles = retrieveFiles(theObject, theFiles)
};
if (theObject.name.match(new RegExp(/\.(jpg|jpeg|png|tif|tiff|psd)/i)) != null) {
theFiles = theFiles.concat(theObject)
}
};
return theFiles
};
//////
function saveCopyAsTif (myDocument, thePath) {
// tif options;
tifOpts = new TiffSaveOptions();
tifOpts.embedColorProfile = true;
tifOpts.imageCompression = TIFFEncoding.TIFFLZW;
tifOpts.alphaChannels = false;
tifOpts.byteOrder = ByteOrder.MACOS;
tifOpts.layers = false;
// save copy;
myDocument.saveAs((new File(thePath)), tifOpts, true);
};
//////
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);
}
//////
function zeroPad(n, s) {
n = n.toString();
while (n.length < s) n = '0' + n;
return n;
};