Skip to main content
Participant
October 20, 2022
Question

Combining 2 action scripts. when not script 1 then script 2.

  • October 20, 2022
  • 3 replies
  • 357 views

Hi peeps,

 

I'm creating a script for converting 27.000 white background product images with clipping path to transparent .png files. these images have 2 different types. 
- pruduct image with white background and a clipping path around the product
- effect picture of product in use

Right now i created 2 scripts.
1.  deletes the white background with help from clipping path selection.
2.  just exports as png

The problem i'm facing is that when i run the first script, the script skips the images without a path and keeping them open in tabs. at the moment i need to run another batch on the tabs that were not run through the script. this slows the computer down because out of a batch of 1000 pictures around 30% are images that need to run script 2 and. so that means that 300 tabs of pictures will be open in photoshop.

I would like to combine the 2 script so that when action 1 from script 1 cant be done, then run script 2 for that image.

This topic has been closed for replies.

3 replies

Stephen Marsh
Community Expert
Community Expert
October 22, 2022

@Joeri5E20 - So, how did you go?

Stephen Marsh
Community Expert
Community Expert
October 20, 2022

This will be similar to the following script:

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/if-named-channel-exists-run-action-1-else-create-named-channel-via-action-2-and-run-action-1/m-p/13258277

 

Perhaps something like this:

 

#target photoshop

try {
    activeDocument.pathItems[0].select();
    //alert("A path exists!");
    app.doAction("Action 1", "Action Set 1");

} catch (e) {
    //alert("A path doesn't exist!");
    app.doAction("Action 1", "Action Set 2");
}

 

You will need to change the references to the Actions and Action Sets to match those in your screenshot of the Action panel.

 

P.S. Actions and Scripts are two different things, Photoshop doesn't have "Action Scripts". Your screenshot shows an Action. As there are no conditional path Actions, you'll need a script like the JavaScript above.

Chuck Uebele
Community Expert
Community Expert
October 20, 2022

Frankly, I would not have two scripts. I would rewrite them to be in one script and use an if else statement to handle each file then close each file.