// enable double clicking from the Macintosh Finder or the Windows Explorer #target photoshop // in case we double clicked the file app.bringToFront(); /////////////////////////// // SET-UP // /////////////////////////// // Set the script location var scriptLocation = findScript() + "0"; // A list of file extensions to skip, keep them lower case gFilesToSkip = Array( "db", "xmp", "thm", "txt", "doc", "md0", "tb0", "adobebridgedb", "adobebridgedbt", "bc", "bct" ); /////////////////////////// // MAIN // /////////////////////////// main(); /////////////////////////// // FUNCTIONS // /////////////////////////// function main(){ if (documents.length > 0){ alert ("This script requires that there are no open documents to run."); return; } // Pops open a dialog for the user to choose the folder of documents to process var inputFolder = Folder.selectDialog("Select a folder of documents to process"); // Pops open a dialog for the user to set the output folder var outputFolder = Folder.selectDialog("Select a folder for the output files"); // Open and process a folder of Images OpenFolder(outputFolder, inputFolder); } // Given the a Folder of files, open them function OpenFolder(outputFolder, inputFolder) { // Generate LOG File var LOGFilePath = outputFolder + "/" + "imagedata.LOG"; var LOGFile = File(LOGFilePath); LOGFile.remove(); var LOGFilePath = new File(outputFolder + "/" + "imagedata.LOG"); var filesOpened = 0; var fileList = inputFolder.getFiles(); for ( var i = 0; i < fileList.length; i++ ) { // Make sure all the files in the folder are compatible with PS if ( fileList[i] instanceof File && ! fileList[i].hidden && ! IsFileOneOfThese( fileList[i], gFilesToSkip )) { open( fileList[i] ); filesOpened++; var docRef = activeDocument; var myImage = docRef.name cropAndStraighten(); docRef.close(SaveOptions.DONOTSAVECHANGES); // Check to make sure the right number of images were cropped if (app.documents.length > 2) { writeImageCountLog(LOGFile, myImage); } while (app.documents.length >=1){ app.activeDocument.flatten(); saveJPG(outputFolder); // Check the image sizes of the cropped images if (app.activeDocument.height.value > 600 || app.activeDocument.height.value < 1000 ) { writeImageSizeLog(LOGFile, myImage); } fileClose(SaveOptions.DONOTSAVECHANGES); } } } return filesOpened; } // given a file name and a list of extensions // determine if this file is in the list of extensions function IsFileOneOfThese( inFileName, inArrayOfFileExtensions ) { var lastDot = inFileName.toString().lastIndexOf( "." ); if ( lastDot == -1 ) { return false; } var strLength = inFileName.toString().length; var extension = inFileName.toString().substr( lastDot + 1, strLength - lastDot ); extension = extension.toLowerCase(); for (var i = 0; i < inArrayOfFileExtensions.length; i++ ) { if ( extension == inArrayOfFileExtensions[i] ) { return true; } } return false; } // fileClose function for closing current document function fileClose(options) { app.activeDocument.close(options); } // Crop and Straighten function cropAndStraighten(){ var id333 = stringIDToTypeID( "CropPhotosAuto0001" ); executeAction( id333, undefined, DialogModes.NO ); } // Save JPG function saveJPG(filePath){ var id43 = charIDToTypeID( "save" ); var desc11 = new ActionDescriptor(); var id44 = charIDToTypeID( "As " ); var desc12 = new ActionDescriptor(); var id45 = charIDToTypeID( "EQlt" ); desc12.putInteger( id45, 10 ); var id46 = charIDToTypeID( "MttC" ); var id47 = charIDToTypeID( "MttC" ); var id48 = charIDToTypeID( "None" ); desc12.putEnumerated( id46, id47, id48 ); var id49 = charIDToTypeID( "JPEG" ); desc11.putObject( id44, id49, desc12 ); var id50 = charIDToTypeID( "In " ); desc11.putPath( id50, new File( filePath ) ); var id51 = charIDToTypeID( "LwCs" ); desc11.putBoolean( id51, true ); executeAction( id43, desc11, DialogModes.NO ); } // Write out image name LOG function writeLOGDocRef(fileType) { LOGFile = fileType; writeLOG("" + app.activeDocument.name + "" + "\n"); } // Write LOG file function writeLOG(log) { try { if(LOGFile.exists) { LOGFile.open ("e"); LOGFile.seek (0,2); // Move to EOF } else { LOGFile.open ("w"); // Add unicode marker if we change to LOG file format for this log file } LOGFile.encoding = "UTF8"; // set UTF8 LOGFile.write(log); LOGFile.close(); } catch (e) { alert(e); } finally { } return; } // Write out Image Count Log function writeImageCountLog(fileType, myImage) { LOGFile = fileType; writeLOG("Too many images returned from crop on: " + myImage + "\n"); } // Write out Image Count Log function writeImageSizeLog(fileType, myImage) { LOGFile = fileType; writeLOG("Incorrect Image Size returned from crop on: " + myImage + "\n"); }