Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Trying to write a script/sequence of actions that does a better job of processing ganged-up photos

Community Beginner ,
Oct 19, 2021 Oct 19, 2021

Copy link to clipboard

Copied

I have an aunt who has given me something like 8000 photos individually that need to be scanned multi-upped on a platen glass and then processed via essentially 'crop and straighten' from the photoshop built-in scripts. The issue I'm having is occasionally crop/straighten will cut an image with 4 photos into like 7-12 images instead of the initial 4 (It detects smaller images that don't exist, and occasionally cuts photos in half) I can fix this in the future by not using a white background behind the photos (I've heard a really bright red works really well) but in the meantime I've already scanned about 2000 photos that I need to process. 

I actually had built/edited a script back in 2018 and it worked really well, but updates got me and it's gone now. I've looked everywhere and the script I was originally using was the one I've seen all over that utilizes the below code:

#target Photoshop
app.bringToFront;
var inFolder = Folder.selectDialog("Please select folder to process");
if(inFolder != null){
var fileList = inFolder.getFiles(/\.(jpg|tif|psd|jpeg|)$/i);
var outfolder = new Folder(decodeURI(inFolder) + "/Completed");
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) + ".jpg");
SaveJPEG(saveFile, 12);
activeDocument.close(SaveOptions.DONOTSAVECHANGES) ;
count++;
}
}
}
};
function CropStraighten() {
executeAction( stringIDToTypeID('CropPhotosAuto0001'), undefined, DialogModes.NO );
};
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;
};

However as I'm trying to bypass the built in crop straighten (CropPhotosAuto0001)and use a custom action I've made that uses selection boxes to map specific area of the image, and then does crop/straighten on just that area (This reduces the errors and split images from the original above)

#target Photoshop
app.bringToFront;
var inFolder = Folder.selectDialog("Please select folder to process");
if(inFolder != null){
var fileList = inFolder.getFiles(/\.(jpg|tif|psd|jpeg|)$/i);
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) + ".jpg");
SaveJPEG(saveFile, 12);
activeDocument.close(SaveOptions.DONOTSAVECHANGES) ;
count++;
}
}
}
};
function CropStraighten() {
executeAction( stringIDToTypeID('Photo_Split'), undefined, DialogModes.NO );
};
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;
};

Photo Split is the custom action I have created - This above is the code that I have been trying to run - the only change was basically instead of calling the "CropPhotosAuto0001" in the stringIDToTypeID; I'm calling my custom action, which does have a stringID and does have a type ID. as per a logTerminology.jsx  to find all the ID's in a string format. however when I try to run the full script I'm getting an error:


- The command"<unknown>"> is not currently available
Line: 26
-> executeAction( stringIDToTypeID('Photo_Split'), undefined, DialogModes.NO );

I'm okay at reading code and making minor tweaks, but my depth of understanding is fairly limited so I feel like I'm running in circles looking at this, and I'm not even sure if I can call a custom action to execute, but I thought that the CropPhotosAuto0001 would be an action, so I thought it would be easily interchangeable.

All of this basically comes from the issue that the original script does exactly what I want but not with a enough accuracy, as I will have to go back and find and re-do potentially hundreds of specific images which will take me hours of time. 

If this is a pipe dream that is fine - I guess the alternative would be if anyone has a good script that saves all open documents without overwriting, as using Save As as an action just saves the same names repeatedly. I've been looking but haven't found one that suits my needs yet.

I have tried using batch - however the problem comes from opening one document and trying to save 5 - batch is trying to save every one of the images generated under the same file name, so even though its giving me all the file save options, every image is saving to the same fancy file name. 

TOPICS
Actions and scripting

Views

154

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Oct 19, 2021 Oct 19, 2021
have you replaced the "Your action set name" argument with the name of your action set? for example: app.doAction("Photo_Split","Set 1")  

Likes

Translate

Translate
Adobe Community Professional ,
Oct 19, 2021 Oct 19, 2021

Copy link to clipboard

Copied

What do you mean when you write the word "action"? If this is an action in the Actions palette, then it can be runned with the command: app.doAction ("Photo_Split", "Your action set name")

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 19, 2021 Oct 19, 2021

Copy link to clipboard

Copied

when referring to my sequence of actions that I've done to try and circumvent the crop/straighten script built in - It is an action I've built in the action palette. (Select / Crop Straighten / Return to first image, repeated 4 times - One for each selected quadrant of the scanned image) Leaving me with essentially the same output as the original crop/straighten script. 

I did just try it with that command in lieu of the crop function I had before and I got a return of "The command 'play' is not currently available."

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Oct 19, 2021 Oct 19, 2021

Copy link to clipboard

Copied

have you replaced the "Your action set name" argument with the name of your action set?

for example:

app.doAction("Photo_Split","Set 1")

 2021-10-19_23-11-07.png

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 19, 2021 Oct 19, 2021

Copy link to clipboard

Copied

And all along it was because I had a naming issue where I had named it Photo Split / Photo Splitting - but in the code I assumed I needed an underscore to show the space.

It is now working completely. Thank you for your assistance. 🙂

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Oct 19, 2021 Oct 19, 2021

Copy link to clipboard

Copied

So which line in your code you corrected to make script working as intended?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 19, 2021 Oct 19, 2021

Copy link to clipboard

Copied

All I corrected was my naming for the "app.doAction("Photo Split", "Photo Splitting")" I just needed to remove the Underscore.

I might play with my original code and see if removing the underscore in the original still runs the appropriate action from the stringIDs

The final code is:

#target Photoshop
app.bringToFront;

var inFolder = Folder.selectDialog("Please select folder to process");

if (inFolder != null) {
	var fileList = inFolder.getFiles(/\.(jpg|tif|psd|jpeg|)$/i);
	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);
			app.doAction("Photo Split", "Photo Splitting")
			doc.close(SaveOptions.DONOTSAVECHANGES);
			
			var count = 1; while(app.documents.length) {
				var saveFile = new File(decodeURI(outfolder) + "/" + docname +"#"+ zeroPad(count, 3) + ".jpg");
				SaveJPEG(saveFile, 12), activeDocument.close(SaveOptions.DONOTSAVECHANGES), count++;
			}
		}
	}
}

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;
}


This asks what folder to process photos from, runs my custom action which essentially does the same thing as the built in crop and straighten except in my action I have added a selection that cuts down on external noise like other photos or things in the background which might mess with the photo border detection. It then saves all of the photos that were processed in another folder (In this case - /edited)

For the actions its just a matter of selecting the areas you want to process (in my case, 4 areas in the files im processing are the same location for each individual photo is in each file) Then setting up crop/straighten as an action, and then returning after each selection/crop to the first page, then running the same action again but with a different selection area. At the end you'll have 1 file open which is the original 4 up, and then however many selections/actions you made - at this point the script takes over again and saves them all individually named. 


I've included a link below to download the ATN file - so you can easily load my action into your photoshop 🙂


Photo Splitting.atn

 

Good luck for anyone who needs to use it in the future.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Oct 20, 2021 Oct 20, 2021

Copy link to clipboard

Copied

LATEST

I think jazz-y answer deserves to be marked as correct solution, doesn't it?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines