When running that command (from the file menu; not from the script) on a single scanned image, Photoshop will sometimes think it has found multiple images if the photo contains objects with "edges." To overcome this, you can hold down the "Alt" key (Windows) when selecting the command, thereby telling Photoshop that you are working with only one photo. (See the tip at <http://livedocs.adobe.com/en_US/Photoshop/10.0/help.html?content=WSfd1234e1c4b69f30ea53e41001031ab64-762e.html.)> Unfortunately, this "Alt" key option is not captured when recording an action. Is there any way to incorporate this into the script provided here?
Thanks!
Here I am, looking for a complicated scripting solution, when the easy solution is right in front of me. This solution is brilliant!
I will try it tonight.
Thank you!
Here's the full script. Hope this helps someone!
===========================
// Prompts the user for a directory, and then recursively processes each image
// in that directory and all subdirectories by executing the "Crop and
// Straighten" command. Images are saved with a specified suffix in a
// designated subfolder.
// Adapted from a script provided by "Paul R." in the "Photoshop Scripting" forum
// <http://www.adobeforums.com/webx?7@@.59b54905/2>
// TIP: Hold down the "Alt" key while running this script to instruct Photoshop
// to treat the image as a single photo. (For more information, see:
// <http://livedocs.adobe.com/en_US/Photoshop/10.0/help.html?content=WSfd1234e1c4b69f30ea53e41001031ab64-762e.html)>
#target Photoshop
app.bringToFront;
var inputFolder = Folder.selectDialog("Please select folder to process");
if(inputFolder != null){
ProcessFiles(inputFolder);
};
function ProcessFiles(inFolder) {
// var fileList = inFolder.getFiles(/\.(jpg|tif||psd|)$/i);
var fileList = inFolder.getFiles();
var outfolder = new Folder(decodeURI(inFolder) + "/Cropped");
if (outfolder.exists == false) outfolder.create();
for(var a = 0 ;a < fileList.length; a++){ if(fileList[a] instanceof File && fileList[a].name.match(/\.(jpg|tif||psd|)$/i)){ 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"); var saveFile = new File(decodeURI(outfolder) + "/" + docname + "-CR"+ ".tif"); SaveTIFF(saveFile); activeDocument.close(SaveOptions.DONOTSAVECHANGES) ; count++; } } else if (fileList[a] instanceof Folder) { // alert("Folder: " + fileList[a]); ProcessFiles(fileList[a]) } else { // inappropriate file type, or null } } };
function CropStraighten() {
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };
executeAction( sTID('CropPhotosAuto0001'), undefined, DialogModes.NO );
};
function SaveTIFF(saveFile){
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.embedColorProfile = true;
tiffSaveOptions.alphaChannels = true;
tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;
activeDocument.saveAs(saveFile, tiffSaveOptions, false, Extension.LOWERCASE);
};
function zeroPad(n, s) {
n = n.toString();
while (n.length < s) n = '0' + n; return n; };