Incrementing filenames within actions

Discussion of Automation, Image Workflow and Raw Image Workflow

Moderators: Tom, Kukurykus

Barrykap

Incrementing filenames within actions

Post by Barrykap »

Hi

I'm new here and also new to scripting although I have been doing actions for a while now in Photoshop (CS2).

I have a little problem and wondered if it can be solved by an action or a script.

I have thousands of A4 photos to scan and save on the PC. I am trying to speed up the actual scanning and saving to maybe just one keystroke per photo via an action function. So I can set the action to scan and save the scan then close the image ready for the next scan when I have swapped photos in the scanner.

I would PREFER to have all the scans in one folder, numbered in some way sequentially. eg; Untitled-1, untitled-2 etc would do fine as I will later re-open each in turn to crop, retouch and re-save as a 'proper filename'. My main concern as I said is speeding up the actual scanning.

I have tried an action where it imports via activating the scanner twain, scans at the correct resolution etc and then saves and closes the file. But of course the next time I run the action it creates 'untitled-1' again and so it will overwrite the previous one (or will stop and ask me to confirm it should be overwritten which I DO NOT want it to do). I need really some way to increment the 'untitled' numbers automatically as I do a new scan. ie it will maybe see I already have 'untitled-1' and so automatically increment it to 'untitled-2'. Is this possible?

I tried a way of creating a new folder within the same action and at first it created 'New Folder' then the second time it created 'New Folder(2)' and the files (both named 'untitled-1') were saved in these folders. That would have sufficed as at least I had a list of folders incremented each time with all my scans (named 'untitled-1') saved inside each folder separately. But for some reason it stops after Folder(2) and just kept overwriting the new scan into this same folder. Don't know whether it was because I was using the same photo every time for each new test scan, but it didn't seem to work very well.

I hope you can see what I am trying to do.

I really need to get something working with just one keystroke as I have lot to do and the biggest labour time will be in opening the scanner and replacing photos. I don't want to also have to sit at the keyboard traversing folders and renaming files manually too.

Many thanks if anyone can help me.

Best regards,

Barry

Ps. I may also point out that I know I can do a series of scans while leaving them open in Photoshop, thus creating 'untitled-1', 'untitled-2'.... etc' Then close them all in one operation afterwards. But I don't wish to do the thousands of scans all in one go, so the next time I start scanning I will be back to 'untitled-1' again. Need to have continuity in incrementing the filenames carrying on from subsequent sessions. Thanks.
Mike Hale

Incrementing filenames within actions

Post by Mike Hale »

I do this kind of thing almost everyday. I found the best way, at least for me, is to batch scan as many prints as you have time/memory for then batch run a save action on the open docs using the File Naming option to pick up the number where you left of the last batch.

It's a lot faster than scanning one print at a time and there is not any real advantage to using a script.

Mike
Barrykap

Incrementing filenames within actions

Post by Barrykap »

Thanks Mike.

Yes I used to do batch scanning then saved the lot to one folder (untitled-1 to last one done).

But not sure how to recommence from an earlier 'untitled-n'. Can you explain please?

I would not wnat to sit and manually change each file name.

Is this something in PS I have not come across yet?

Cheers.

Barry.
Mike Hale

Incrementing filenames within actions

Post by Mike Hale »

Here is what I do. I have several actions for saving files. One for psd, one for tif and a couple for jpg at different quality setting. You can get by will just one. The action saves then closes an open doc.

After I have scanned a batch of prints I select the action for the file type I need for that customer. I then go to the File-Automate-Batch menu. In that dialog I choose Open Files in the Source section, Folder in the Destination, and check the Override Save As Commands.

In the File Naming section I enter the customer's name in the first box (You could enter Untitled ), a - in the second box, 2 0r 3 Digit Serial Number in the third box ( depending on the total number of files I will end up with), and extension in the fourth box.

The first batch I make sure 1 is in the Starting serial#. For the next batch I change that to whatever is needed to resume.

It does require me to jot down the last number used but I find it more flexible than a script

Mike
Barrykap

Incrementing filenames within actions

Post by Barrykap »

Thanks a lot Mike.

I'll give that a whirl.

Regards,

Barry
Barrykap

Incrementing filenames within actions

Post by Barrykap »

Hi Mike

Tried your suggestion.

Can't seem to get it to work properly.

Couple of probs;-

Say I scan three photos so have 'untitled-1'.....'untitled-3' open on screen with the last one scanned 'active' ie untitled-3

Running batch automation I set the filenaming as '4-digit serial number' in first box (which really is all I need) plus the extension, which I don't identify as JPG (as the scans are in JPG) - not sure where you enter teh actual extension filetype anyway.

If I tick the 'overide save-as' box it will run and the images disappear. But none are saved.

If I untick this box, the 'save-as box' pops up, the last one open (untitled-3) is offered as '0001.jpg'.

So it's saving in reverse to how they were opened and I can't have this as I need to keep them all in the order of scanning to match the order they are filed in the album.

When I untick or tick the overide box it pops up with a window which frankly completely confuses me about 'save-as'. Saying something like 'if no save-as steps in the action are selected it will not save files'

Just can't get my head round that one!

Any comments?

And thanks for your time on this.

Cheers.

barry.
Mike Hale

Incrementing filenames within actions

Post by Mike Hale »

The scan order is not an issue for me so I didn't notice that.

Try this script.

Code: Select allfunction whereAmI() {
   var where;
   try {
      var forcedError = FORCEDRRROR;
   }
   catch( e ) {
      where = File(e.fileName).parent;
   }
   return where;
}
// define an ini file to save last/next number
var ini = new File(whereAmI()+'/temp.ini');
//look for ini file
if(ini.exists){// found it
   ini.open('r');
   var startNumber = new Number(ini.readln());
   var saveFolder = new Folder(ini.readln());
   ini.close();
}else{// no ini file - set defaults
   var startNumber = 1;
   var saveFolder = Folder.selectDialog("Select a folder to save scans");
}
// other defaults
var savePrefix = 'Untitled-';
saveOptions = new JPEGSaveOptions();
saveOptions.embedColorProfile = true;
saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
saveOptions.matte = MatteType.NONE;
saveOptions.quality = 8;   

while(documents.length > 0){// save and close the open docs in the order they where opened/created/imported
   var t = documents[0];
   t.saveAs(new File(saveFolder+'/'+savePrefix+startNumber+'.jpg'), saveOptions, true,Extension.LOWERCASE);
   t.close(SaveOptions.DONOTSAVECHANGES);
   startNumber++;
}
//save the settings for next run
ini.open('w');
ini.writeln(startNumber);
ini.writeln(saveFolder);
ini.close();

Mike
Barrykap

Incrementing filenames within actions

Post by Barrykap »

Hi Mike

Thanks very much for the suggestion.

I tried the script first with no scans open, just to see what happened.

It first offered me a window to choose the folder for saving so I then decided it looks like working, so abandoned it and set about scanning a few tests in and leaving them open.

I then ran the script again (load script) but it then came up with error;-



I then cleared all the images again and thought I would try it as I did originally and see what happens after choosing a folder. But this time absolutely nothing happens when I load the script.

I have noticed this before with CS2. I can run something seemingly 'OK' just the once, then any subsequent runs just fails. Don't know if it is my CS2 or what or whether creating the error condition has fouled up the script?

I am not familiar with scripts at all realy.

Anyway, not being able to do anything more with it I tried another approach which was the create folders named 0, 10, 20, 30 etc and do a scanning batch of ten photos at a time, thus getting 'untitled-1' .... untitled-10' open on screen. I then have to select the first folder (0) and save them all to this folder. I then do another 'batch' and save to (10) folder etc etc.

This will suffice initially as I will then have my sets of tens scanned in numerical order.

When I open each file later for cropping etc I then save-as the proper filename in a different folder.

I can set up an action to save them all of course but it is selecting the folder which is the problem. It needs to set as the default folder to save into and not sure how to do this as there will be no files in the folders initailly so I can't 'open' anything to make the folder the default (current) folder if you follow.

Anyway, I am sorry I keep asking you for help and will understand if you don't want to offer any further time. I am grateful for what you have given me so far.

If the worst happens I will just have to save the ten manually. Maybe doing the first one manually (to select the default folder to save in) then the other nine automatically (as the correct folder will then be the default).

Many thanks.

Barry.
Mike Hale

Incrementing filenames within actions

Post by Mike Hale »

I'll admit I did not use any error checking. My guess is that you abandoned it by closing the folder browse dialog without selection a folder. Because of that, bad data was written to the ini file.

A quick fix would be to delete the ini file. It's in the same folder where you saved the script. Then only run the script after you have done a batch of scans.

Or you could add a few checks to make sure that there are open docs, the user didn't cancel the dialog, and that the saveFolder exists.

Mike
Barrykap

Incrementing filenames within actions

Post by Barrykap »

Tnaks Mike.

I'll check that out tomorrow.

I've also been given another 'tip' to try and I'll explain that when I have had a chance to try it out, but only if your script doesn't work.

Cheers.

Barry.