Skip to main content
Participant
May 25, 2015
Question

Need help writing a script that batch proccesses images in a folder with different PS actions based on their name by referring to a CSV file.

  • May 25, 2015
  • 1 reply
  • 978 views

The short story...
I need help writing a script that when ran will check a certain folder for new images then apply different actions to them in Photoshop based on their filename. i was thinking that using a CSV file (that we would create in excel) to refer to would be the best way to do this but I'm only a beginner at JavaScript and really have no clue how id refer to the csv file in JavaScript language. if someone could point me in the right direction that would be appreciated (I have looked all over and cant seem to find anything specific to my problem).

The reason for this all is?

I work for a canvas art/ portrait photography shop and we need to process many images a day using custom actions that move, resize and crop the image to fit print file dimensions. this currently needs someone to sit and set each action off to each image (The action names are also part of our Image codes in filename, this is how we would refer to them in the CSV file and this is how the worker currently knows which action to set off on which file)

Sometimes there are exceptions to this and an image needs to have two actions set off at once (one to resize the other to change Hue). This adds complication to referring to CSV file as each image has multiple codes in its file name (one is product code for example and isn't used in this process) and so they aren't just named the same as the action that is ran off on them which would make the process easier and probably wouldn't require the CSV file.

As I've said any help on the issue would be appreciated.

Jack.

This topic has been closed for replies.

1 reply

Chuck Uebele
Community Expert
Community Expert
May 26, 2015

So would the file name be in the CSV file? or are just a list of actions in that file? What I'm trying to get as is do you need the CSV file. It sounds like you have your actions listed in the image's file name, so you just need to break down the file name and have the right action run from that. Using the "switch" function in javascript would take care of this.

var actionToUse = 'some section of file name'

switch(actionToUse){

     case: 'some setion of file name 1'

     //code to run action 1

     break;

     case: 'some setion of file name 2'

     //code to run action 2

     break;

}

jackb58Author
Participant
May 26, 2015

Hello thank you for your time and response.

It seems the CSV file might not be needed then based on your answer, you are correct in assuming that the name of the action is in the filename.

The end result i am hoping to achieve is a script that (when opened) applies the correct actions to images in a drop-box style folder and then moves them to another folder after the action is ran off on them.

The script needs to be able to distinguish which action to run on the image based on the last 6 characters of the filename (which is the name of the action to be ran off)

Your suggestion of the "switch" function has progressed my understanding of how to do this but i still feel like i am missing certain elements of how to pull it all together into a working script

I would like script to search the filenames of each image in the folder for the code that it would use to reference the action to be ran off on them.

How would i accomplish this?

Chuck Uebele
Community Expert
Community Expert
May 26, 2015

Two ways you can do this. You can make a script that will work on a single image, then use the batch script or image processor to run a batch of files (you need to assign your script to an action for this to work). Or you can write a script that will take a folder full of images and process them all.

To not have to use the batch script you need to put into your script the code that will get all files and tell if they are files or folders, and the right type of files. You can look at scripts like image processor to see how this is done on both Win and Mac systems. Lets just say you know all the files are ones you want in a particular folder. You would use something like:

var myFolder = new Folder('/c/my folder path/');

var searchMask = '*.???';//use whatever search is best for you. if all the files are NEF, use that.

selectedFiles = myFolder.getFiles(searchMask);

You can then write a function to check the files for the proper type, as mentioned above. Then you loop through the files and find out which ones get what processing:

for(var i=0;i<selectedFiles.length;i++){

var fileName= selectedFiles.name.split('.')[0];//assumes that you only have one dot in the file name for the extension.

var suffix = fileName..substring(docName.length - 6, docName.length).toUpperCase();//turn it to upper case to they're all the same.

switch(suffix){

     case: 'action1'

     //your code here

     break;

     case: 'action2'

     //your code here

     break;

     }

};