How do you know what action selected in the panel Аct

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Mike Hale

How do you know what action selected in the panel Аct

Post by Mike Hale »

This is not be fully tested but seems to work with my limited number of actionSets.
Code: Select allgetSelectedAction()
function getSelectedAction(){
    var ref = new ActionReference();
    ref.putEnumerated( charIDToTypeID("Actn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
    var desc = executeActionGet(ref);
    var selectedName = desc.getString(charIDToTypeID("Nm  "));
    var selectedIndex = desc.getInteger(charIDToTypeID("ItmI"));
    var parentName = desc.getString(charIDToTypeID("PrNm"));
    var parentIndex = desc.getInteger(charIDToTypeID("PrIn"));
    if(isActionSet( parentIndex, parentName )){
        var setName = parentName;
        var actionName = selectedName;
    }else{
        var setName = findAction(parentIndex, parentName );
        var actionName = parentName;
    }
    return [setName,actionName];
};
function isActionSet( parentIndex, parentName ){
   var res = false;
   try{
      var ref = new ActionReference();
      ref.putIndex( charIDToTypeID( "ASet" ), parentIndex );
      var setName = executeActionGet( ref ).getString(charIDToTypeID("Nm  "));
      if(setName == parentName) res = true;
   }catch(e){}
   return res;
};
function findAction(parentIndex, parentName ) {
  var i = 1;
  var found = false;
  while (!found) {
    var ref = new ActionReference();
    ref.putIndex(charIDToTypeID('ASet'), i);
    var desc;
    try {
      desc = executeActionGet(ref);
    } catch (e) {
      break;
    } finally {
    }
    if (desc.hasKey(charIDToTypeID('Nm  '))) { ;
      var setName = desc.getString(charIDToTypeID('Nm  '));
        var ref = new ActionReference();
        ref.putIndex(charIDToTypeID('Actn'), parentIndex);
        ref.putIndex(charIDToTypeID('ASet'), i);
        try{
        var adesc = executeActionGet(ref);
        var actName = adesc.getString(charIDToTypeID('Nm  '));
        if(actName==parentName) return setName;
        }catch(e){}
      }
    i++;
    }
};

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

stat

How do you know what action selected in the panel Аct

Post by stat »

YEEESSS!!!
Superrrr!
Thank you very much.
Tell me please, why this code not work?

var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("ASet"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
var selectedName = desc.getString(charIDToTypeID("Nm "));

I want to print the name of the selected ActionSet
Mike Hale

How do you know what action selected in the panel Аct

Post by Mike Hale »

This is just a guess but I think it is because an action set can never be the target of an executeAction. Unlike layerSets, there is nothing you can do to an action set that is recordable where the set is the target. Deleting an action set is logged by scriptlistener but it is referenced by name.

You can also reference an action set by index but I don't see a way to tell if it is selected.

Even in the GUI having just an action set selected is ignored by the Batch command. If an action or action step is selected Batch fills the selected set and action. If an action set is selected it defaults to the first set and first action.
stat

How do you know what action selected in the panel Аct

Post by stat »

many thanks for the explanation. I knew it!