What's new
Photoshop Gurus Forum

Welcome to Photoshop Gurus forum. Register a free account today to become a member! It's completely free. Once signed in, you'll enjoy an ad-free experience and be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Scripting Script to run Actions according to the files names


elgato74

Member
Messages
11
Likes
0
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 ( one-by-one ) in Photoshop and then run actions ( already created ) according to their file names. So for example, if the file name has the "-4LP" in it, the action named "Create4LP" is triggered. If the name has the "-3P" in it, the action "Create3P" is triggered.


Can this be done with a script ?


Thanks muchly !!

Felix
 
Last edited:

thebestcpu

Guru
Messages
2,373
Likes
2,200
Hi elgato74

This can be done by a script (I'm not too proficient at scripts) yet there is another way without a script.

Sort and move each type of file to its own folder and run the Batch Action command against the folder with the desired Action.

That is the quick and dirty way. If what you are going to do is on a massive regular production basis, then a script in PS and/or a script external to PS could do the job as well.

John Wheeler
 

elgato74

Member
Messages
11
Likes
0
Hi there John,

thanks for that, but that does not quite solve it :(

I have to do this task regularly and i dont want to always sort the files into folders every time.
 

MrToM

Guru
Messages
3,504
Likes
3,228
OK.

Try this...

1. You MUST place ALL your ACTIONS in a SET and name it 'ScriptActions'. (No quotes and case sensitive)
2. Unzip the script to a location suitable for your workflow.
3. Run the script.

You will be prompted for the folder containing the images....select it and click OK.

The script will then go through each file in that folder, open it and apply the action with the same name.
If the action does not exist you will get an error message.
On confirming the error you will then get a dialog informing you which action is missing.

You will be responsible for saving the resulting documents, ie record it in each Action.

View attachment run_action_from_filename_MT_01.zip

Regards.
MrTom.
 
Last edited:

elgato74

Member
Messages
11
Likes
0
Hi MrTom

Thank you!

Before I try this out, here are some more details.

I have 8 actions. Their names are:

Create1K
Create1P
CreateMFP
Create3P
CreatePano
Create4LP
Create5P
Create4erP

I will move those actions into a new set called "ScriptActions"

In my folder I have following sample files:

CSC-1K.jpg
ARX-1K.jpg
DNZ-1P.jpg
CLH-4erP.jpg
CQW-4erP.jpg
CUN-4LP.jpg
DTR-5P.jpg
AYH-MFP.jpg
CCR-MFP.jpg
BPN-MFP.jpg
CUF-MFP.jpg
DSR-Pano.jpg
APE-Pano.jpg
DHU-Pano.jpg
AIE-4erP.jpg
BDR-MFP.jpg
ARW-MFP.jpg
EII-MFP.jpg
CDZ-1P.jpg


Is this good ?

And: the 8 actions above do also include some other actions. Will this cause a problem ?
 
Last edited:

MrToM

Guru
Messages
3,504
Likes
3,228
...Is this good ?

And: the 8 actions above do also include some other actions. Will this cause a problem ?...
I couldn't possibly say.

The script does as you asked, if you have the wrong filename or the wrong Action name then it will fail....you'll have to make sure your files are in order.

From your list I see no reason why it shouldn't work, as long as there is a matching Action for each filename then it should be good.

I see no reason why additional actions wouldn't work, the next file isn't processed until the last one is finished.

You'll just have to try it and see with the files you have, I can only try it on a limited basis here.

The script doesn't save anything so you can try it without fear of anything happening to your files....your Actions though are your responsibility.

You MUST create the SET as described as scripts need this to be able to run Actions....sorry but there is no alternative to this.

Regards.
MrToM.
 
Last edited:

Paul MR

The Script Master
Messages
382
Likes
206
Here is another version.
Code:
#target photoshop;
if(documents.length){
//AMEND THE LINE BELOW WITH YOUR ACTIONSET NAME
var actionsetName =   "Your Action Set Name"; 
var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
try{
var action = "Create" + Name.match(/[^\/|^-]+$/);
app.doAction (action, actionsetName);
}catch(e){alert(e + "\n" + e.line);}
    }

Make sure you change the actionsetName to what your actions are saved in!
Once the script has been saved you can then create an action to run it using "Insert Menu Iten" from the action palette fly out menu, then Files - Scripts - select the script.

You can now use this via Image Processor / manually call it or even set up Files - Scripts - Scripts Event Manager to call the action with the Photoshop Event set to "Open Document" It will then run automatically when you open a document.
 

elgato74

Member
Messages
11
Likes
0
I just tried it .... and ... WOW !!!!

It totally works ! Thank you so so much !
 
Last edited:

Top