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

Listener trigger "play" argument actionSet is wrong value

Enthusiast ,
Mar 01, 2019 Mar 01, 2019

Copy link to clipboard

Copied

I created a photoshop listener (Script Events Manager) to trigger which action is played (from the actions panel list) when the user runs it.

The listener fires well and I want to get the 2 vars:

A) Name of the action Set just triggered;

B) Name of the Action just triggered;

We use this to send the result to an external database that collects the Photo-editor history log, and I want to send the set and the action name.

This is the AM code from scriptlistener:

// ______________________

var descriptor = new ActionDescriptor();

var reference = new ActionReference();

reference.putName( stringIDToTypeID( "action" ), “MyAction Name here" );

reference.putName( stringIDToTypeID( "actionSet" ), “MySetName here" );

descriptor.putReference( charIDToTypeID( "null" ), reference );

executeAction( stringIDToTypeID( "play" ), descriptor, DialogModes.NO );

// ______________________

The listener is installed and it runs a script I named “actionPlayed_listener.jsx"

if (BridgeTalk.appName == "photoshop"){

  app.notifiersEnabled = true;

  var cstoolEvent = new File(Folder.desktop + "/actionPlayed_listener.jsx");

  try{

  app.notifiers.add("Ply ", cstoolEvent);

  }catch(e){}

}

// the code in the actionPlayed_listener.jsx file:

var myDescriptor = arguments[0].getReference(stringIDToTypeID("null"));

var actionSet_name = myDescriptor.hasKey(stringIDToTypeID("actionSet"));

var action_name = myDescriptor.getName(stringIDToTypeID("action"));

alert(

"Set: " + actionSet_name + "\n"

+ "Action: " + action_name

);

What’s the problem?

actionSet_name ERROR: It returns the name of the action and not the actionSet name!

action_name returns the name of the action

I tested on CC2017 (mac and PC)

Have you another way of return to correct value, or is this a bug we can’t solve?

TOPICS
Actions and scripting

Views

1.7K

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

correct answers 1 Correct answer

People's Champ , Mar 05, 2019 Mar 05, 2019

more correct

// the code in the “actionPlayed_listener.jsx” file:

var r = arguments[0].getReference(stringIDToTypeID("null"));

var x1, x2;

var t1 = r.getDesiredClass();

switch (r.getForm())

    {

    case ReferenceFormType.INDEX: x1 = r.getIndex();  

    case ReferenceFormType.NAME:  x1 = r.getName();   

    }

r = r.getContainer();  // can fail, so use try-catch

var t2 = r.getDesiredClass();

switch (r.getForm())

    {

    case ReferenceFormType.INDEX: x2 = r.getIndex();  

    case ReferenceFormType.NAME: 

...

Votes

Translate

Translate
Adobe
LEGEND ,
Mar 01, 2019 Mar 01, 2019

Copy link to clipboard

Copied

var actionSet_name = myDescriptor.hasKey(stringIDToTypeID("actionSet")); // Change struckthrough part to getName.

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
Enthusiast ,
Mar 01, 2019 Mar 01, 2019

Copy link to clipboard

Copied

Sorry, I wrote the wrong code.

The bug is still there even using getName

var actionSet_name = myDescriptor.getName(stringIDToTypeID("actionSet"));

// returns wrong data

It returns the name of the action, not the name of the Set.

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
LEGEND ,
Mar 01, 2019 Mar 01, 2019

Copy link to clipboard

Copied

So maybe change getName to getString?

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
Enthusiast ,
Mar 01, 2019 Mar 01, 2019

Copy link to clipboard

Copied

getString returns an error because getString is not a method of the ActionReference class

 

Error:

myDescriptor.getString is not a function

 

see:

ActionReference in Photoshop DOM

 

It must be getName

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
People's Champ ,
Mar 02, 2019 Mar 02, 2019

Copy link to clipboard

Copied

"action" can also be an Index type.

use myDescriptor.getForm() to obtain type.

P.S. myDescriptor is an ActionReference you have

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
Enthusiast ,
Mar 05, 2019 Mar 05, 2019

Copy link to clipboard

Copied

I used

myDescriptor.getForm(stringIDToTypeID("actionSet"))

and it returned:

ReferenceFormType.NAME

So getName should be working, but it returns not the name of the set but the action name itself.

It's a bug?

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
People's Champ ,
Mar 05, 2019 Mar 05, 2019

Copy link to clipboard

Copied

You use this function incorrectly.

Try to understand how this code works.

Here r (the ActionReference) emits your myDescriptor and contains similar data,

two or even three values: setName(or index), actionName(or index), cmdIndex(or Name)

// example 1

// ref contains name and name

var r = new ActionReference();

r.putName(stringIDToTypeID("actionSet"), "some S");  

r.putName(stringIDToTypeID("action"), "some A");

var form1 = r.getForm().toString().replace("ReferenceFormType.", "");

//here can use r.getName or r.getIndex, depending on form1

r = r.getContainer();

var form2 = r.getForm().toString().replace("ReferenceFormType.", "");

alert(form1 + "\n" + form2);

//here can use r.getName or r.getIndex, depending on form2

// example 2

// ref contains name and index

var r = new ActionReference();

r.putName(stringIDToTypeID("actionSet"), "some S");  

r.putIndex(stringIDToTypeID("action"), 7);

var form1 = r.getForm().toString().replace("ReferenceFormType.", "");

r = r.getContainer();

var form2 = r.getForm().toString().replace("ReferenceFormType.", "");

alert(form1 + "\n" + form2);

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
Enthusiast ,
Mar 05, 2019 Mar 05, 2019

Copy link to clipboard

Copied

Could you install the "play" listener and use the script it runs instead?

I can't start from a well-defined actionSet and action names because I don't know what action the user has run.

Those are the strings I need to catch when the user clicked an action to run.

I created a listener ("Ply ") that automatically runs a script. This is the script we are talking about.

The code I need is to read the data (both actionSet + action names) and send it to a personal database I need.

So, I must start with arguments[0]   >> this is my ActionDescriptor which contains my ActionReference with both names I need.

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
People's Champ ,
Mar 05, 2019 Mar 05, 2019

Copy link to clipboard

Copied

Oh oh oh

Try

// the code in the “actionPlayed_listener.jsx” file:

var r = arguments[0].getReference(stringIDToTypeID("null"));

var x1, x2;

switch (r.getForm())

    {

    case ReferenceFormType.INDEX: x1 = r.getIndex();  

    case ReferenceFormType.NAME:  x1 = r.getName();   

    }

r = r.getContainer();  // can fail, so use try-catch

switch (r.getForm())

    {

    case ReferenceFormType.INDEX: x2 = r.getIndex();  

    case ReferenceFormType.NAME:  x2 = r.getName();   

    }

alert("Set: " + x2 + "\n" + "Action: " + x1);

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
Enthusiast ,
Mar 05, 2019 Mar 05, 2019

Copy link to clipboard

Copied

LATEST

Finally, thank you very much, r-bin!

Sorry I couldn't figure out earlier.

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
People's Champ ,
Mar 05, 2019 Mar 05, 2019

Copy link to clipboard

Copied

more correct

// the code in the “actionPlayed_listener.jsx” file:

var r = arguments[0].getReference(stringIDToTypeID("null"));

var x1, x2;

var t1 = r.getDesiredClass();

switch (r.getForm())

    {

    case ReferenceFormType.INDEX: x1 = r.getIndex();  

    case ReferenceFormType.NAME:  x1 = r.getName();   

    }

r = r.getContainer();  // can fail, so use try-catch

var t2 = r.getDesiredClass();

switch (r.getForm())

    {

    case ReferenceFormType.INDEX: x2 = r.getIndex();  

    case ReferenceFormType.NAME:  x2 = r.getName();   

    }

alert(typeIDToStringID(t2) + " = " + x2 + "\n" + typeIDToStringID(t1) + " = " + x1);

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