• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

run an action on multiple layers

Participant ,
May 21, 2023 May 21, 2023

Copy link to clipboard

Copied

Hello, Can someone explain to me - who does not yet know how to use scripts in Photoshop - how to get one action to play on multiple layers in photoshop?  Right now, I am creating an action and then running it one by one through all the layers I'd like it to apply to.  thanks.

TOPICS
Actions and scripting , macOS

Views

256

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 21, 2023 May 21, 2023

Copy link to clipboard

Copied

@ilanas2487258 - There are many examples in the forum if you search.

 

The following script requires you to hard-code the action set and action into the script code for selected layers:

 

 
While this one has a GUI and an option for all layers or only selected layers:
 
 
This one from @jazz-y uses the currently selected action set/action on selected layers:
 
//Jazz-y
// Run currently selected action on selected layers.jsx

#target photoshop
var s2t = stringIDToTypeID;


(r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var lrs = executeActionGet(r).getList(p);

(r = new ActionReference()).putEnumerated(s2t('action'), s2t('ordinal'), s2t('targetEnum'));
try {
    try {
        var atn = executeActionGet(r).getString(s2t('name')),
            set = executeActionGet(r).getString(s2t('parentName'));
    }
    catch (e) { throw 'Before start select any action from actions palette!' }

    for (var i = 0; i < lrs.count; i++) {
        (r = new ActionReference()).putIdentifier(s2t('layer'), lrs.getReference(i).getIdentifier(s2t('layerID')));
        (d = new ActionDescriptor()).putReference(s2t('target'), r);
        try { executeAction(s2t('select'), d, DialogModes.NO); } catch (e) { throw e + '\nCannot select layer!' }
        (r = new ActionReference()).putName(s2t('action'), atn);
        r.putName(s2t('actionSet'), set);
        (d = new ActionDescriptor()).putReference(s2t('target'), r);
        try { executeAction(s2t('play'), d) } catch (e) { throw e + '\nCannot play action "' + atn + '" from set "' + set + '"' }
    }
} catch (e) { alert(e) }
 
 Info on saving and running scripts here:
 
  1. Copy the code text to the clipboard
  2. Open a new blank file in a plain-text editor (not in a word processor)
  3. Paste the code in
  4. Save as a plain text format file – .txt
  5. Rename the saved file extension from .txt to .jsx
  6. Install or browse to the .jsx file to run (see below)

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 21, 2023 May 21, 2023

Copy link to clipboard

Copied

LATEST

There are conditional actions which can do the job sometimes. Because of limited set of conditions you could check fro Background layer, for example and stop running action.

 

Here is scenario:

You have Background layer and 10 other layers.

Record action to do something to layer. Thats Action 1. (Action select subject in my screenshot)

Record another action, this is action 2:

step 1  to select bottom most layer (or Background layer) then to select next layer. 

step 2 this step should check whether selected layer is Background layer. If yes then do nothing. If selected layer is not Background layer then play Action 1.

step 3 Record step to select next layer .

Duplicate steps 2 and 3 multiple times or as many as you want because when cycling through layers and playing Action 1 hits Background layer it will stop executing, actually it will do nothing.

conditional action.jpg

You can think further about scenarios and how to use conditional actions, the only limitation is restrictive set of conditions. For now you have script which is more powerful and think no more, actions can not do what script can. I am trying to help solve problem when in rush or no script available.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines