Skip to main content
July 26, 2017
Question

A script to run an action according to the file name

  • July 26, 2017
  • 3 replies
  • 10103 views

Dear All,

I hope someone can help.

I am looking at the following task: I have several .jpg files in a folder. Their names are something like "ADE-4LP.jpg" or "DBA-3P.jpg" or "EFC-1P.jpg"

I would like to open these files in Photoshop and then run actions according to their file names. So for example, if the file name has the -4LP ending, the action named "Create4LP" is triggered. If the name has the -3P ending, the action "Create3P" is triggered and so on.

Can this be done with a script ?

Thanks muchly !!

Felix

This topic has been closed for replies.

3 replies

Stephen Marsh
Community Expert
Community Expert
July 28, 2017

The following script will conditionally run an action, with filename being supported:

Siva's Photoshop Conditional Action: Siva's Photoshop Conditional Action

Download Siva's Photoshop Conditional Action

As there are only one set of Then/If conditions, you will only be able to process 1 filename per script run… However if you insert the script into an action, you can then have the Else condition fire up the script again to populate with the next filename etc to manually cycle through open filenames (untested, just an idea).

Enjoy!

JJMack
Community Expert
Community Expert
July 28, 2017

It does not look like that script allows wild carding in file names which is what I think  the question is asking about.  It does seem to all contains but I do not know if the contains could be made the tail part of the name the is why I included the . as part of the search. in my script. Contains with extension and including a . may be as good as my attempt because I did not check to see if the dot found is the last dot  before the extension. However, the script only support one value not a list of values and a list of actions.

JJMack
Stephen Marsh
Community Expert
Community Expert
July 28, 2017

Hi JJMack, I guess these are valid concerns if you did not test the script against the sample filenames, however simply testing the OP’s filenames with the script appears to work with the criteria that the filename with/without extension contains the following key values in bold+red:

ADE-4LP.jpg | DBA-3P.jpg | EFC-1P.jpg

As I originally mentioned and as you say, it is going to be one condition at a time and not a list, so potentially many batches if there are many different codes in the file names. It is not a completely automated solution, however it is semi-automated and an “out of the box” solution that does not require any scripting knowledge by the end user. The project would be easily completed using this script long before the time that it took to learn scripting, find another free script to fully automate or wait on the good graces of another user to write a custom script.

P.S. As the notes at the original site suggest, a save step should also be included in the action being run.

July 26, 2017

yeah that helps tremendously

c.pfaffenbichler
Community Expert
Community Expert
July 26, 2017

Actually the code presented in the last link should serve you pretty well …

JJMack
Community Expert
Community Expert
July 26, 2017

I posted a script that processes open document  not too long ago I need an action to stack multiple images (opened in ps) into multiple layers If you do not want to open image files in a folder you could hack that script. Basic for loop forward or backwards

#target photoshop
app.bringToFront();

function main() {
	if (!documents.length) return;
	for(var i = 0; i < documents.length - 1; i++) { // for the open document
		app.activeDocument = documents[i]; // switch active document
		if (app.activeDocument.name.indexOf("-4LP.") != -1 ){doAction("Create4LP","actionsetName");}
		if (app.activeDocument.name.indexOf("-3P.") != -1 ){doAction("Create3P","actionsetName");}
	}
}
JJMack
JJMack
Community Expert
Community Expert
July 26, 2017

Yes. A Script can process all open documents retrieve the documents names and compare the names. The scripts can play an Action by name if some compare result is positive. However the action must be able to work when there are other open documents and not mess with the other documents.  The actions need to be well behaved.

JJMack
July 26, 2017

Hi there, thanks for your reply to my thread. Who would write me such a script and how much would it cost ?

JJMack
Community Expert
Community Expert
July 26, 2017

You want the script you should write it.

I have never hired anyone to write a script for me do not know what it would cost. What I need I hack myself. I fine script that do things close to what I want to do and modifty them or hack them myself.  I know Photoshop well but don't actually know javascript.  I look at others code and hammer at it.

JJMack