Naming script

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

LIFAS

Naming script

Post by LIFAS »

I have Photoshop CS1 and 3 and I am looking for a way to animate a process I've been doing. I have thousands of scans, each with multiple photos in each. I can scan them each, but I'd like to name them automatically.

For example, each file includes around 4 images, each to be cropped and saved separately. Let's say it's called scan0001, scan0002, etc. I want to crop it (it won't always be the same size, so this part is not automated), then run a script to rename it as (filename)+a for the first one, (filename)+b for the second one, and so on. The way I see it, I would have a different script for each of the 4 images in a scan: scan0001a, scan0001b, scan0001c, and scan0001d. But when I create an action, it doesn't recognize that I want to KEEP the filename the same and APPEND a letter. So I don't get scan0012a...I always get scan0001a, overwriting my work. I can't figure out how to get batch automation to work for this either since I have to crop and THEN save.

Any suggestions?

Thanks so much in advance for all of your work.

Matt
Paul MR

Naming script

Post by Paul MR »

One way is to save all you scans in a folder and run the following script that will crop all the scans and save them in a folder called Edited off the selected folder. You would be best using CS3.

Code: Select all#target Photoshop
app.bringToFront;
var inFolder = Folder.selectDialog("Please select folder to process");
if(inFolder != null){
var fileList = inFolder.getFiles(/\.(jpg|tif||psd|)$/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) + ".tif");
SaveTIFF(saveFile);
activeDocument.close(SaveOptions.DONOTSAVECHANGES) ;
count++;
      }
   }
   }
};
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;
};
LIFAS

Naming script

Post by LIFAS »

how do I do that? How do I use this script? I only know how to record my own, but would copying and pasting that unicode somewhere work for me? Would it allow me to manually crop each set?

Is there a better way for me to do this besides scanning every photos individually?

Thanks!

Matt
Paul MR

Naming script

Post by Paul MR »

What the script does is take a folder of scanned pictures, there maybe more than one picture in each scan and it will auto crop each picture and save each photo into the edited folder. Eash new file will be named the same as the original plus #001 #002 etc

To run the script, save the code using a text editor or better still ExtendScript Toolkit (This is installed at the same time as Photoshop)
For CS3. Save the code as FileName.jsx and place the script in this folder.
PC:- C:/Program Files/Adobe/Adobe Photoshop CS3/Presets/Scripts/
Mac:- [hard drive]/Applications/Adobe Photoshop CS3/Presets/Scripts/
If you have Photoshop open, close and re-start it, it will then pick up the new script.
To run the script from Photoshop:-
File - Scripts and select the script.
LIFAS

Naming script

Post by LIFAS »

You're fantastic. Hopefully this helps me. I'll copy my files first and give it a shot.

Thank you,
Matt