Skip to main content
Brainiac
February 3, 2020
Answered

DispatchScriptRunner return values

  • February 3, 2020
  • 2 replies
  • 1290 views

Hi,

 

I expect this has been asked before, but I cannot find an answer on the forum.

 

I am using DispatchScriptRunner to call some jsx code. I would like the jsx code to return a value to my C plugin. A PMString would do. 

 

Thanks.

 

P.

This topic has been closed for replies.
Correct answer Manan Joshi

Hi Pickory,

 

As Dirk_Becker rightly mentioned you will need to use the result param. In order to use it you will have to intepret the return data using the get functions of the ScriptData. Try the following to get a string value returned from your jsx code

ScriptRecordData arg;
ScriptData script;
IDFile f(PMString("Macintosh HD:Users:manan:Desktop:demo_script.jsx"));
script.SetFile(f);
ScriptData result;
PMString errorString;            
InterfacePtr<IScriptManager> scriptManager(Utils<IScriptUtils>()->QueryScriptManager(kJavaScriptMgrBoss));
            InterfacePtr<IScriptRunner> scriptRunner(scriptManager, UseDefaultIID());
            Utils<IScriptUtils>()->DispatchScriptRunner( scriptRunner, script,
                                                        arg, result,
                                                        errorString, kTrue);
            PMString retval;
            result.GetPMString(retval);
            CAlert::InformationAlert(retval);

result will be populated by the value that you return from your jsx code, based on its type use the appropriate Get method and you should be good.

 

P.S. :- Have you been able to use DispatchScriptRunner command passing the script as a string, i am not able to do that. If you did please share your code snippet

 

-Manan 

2 replies

Manan JoshiCorrect answer
Adobe Expert
February 3, 2020

Hi Pickory,

 

As Dirk_Becker rightly mentioned you will need to use the result param. In order to use it you will have to intepret the return data using the get functions of the ScriptData. Try the following to get a string value returned from your jsx code

ScriptRecordData arg;
ScriptData script;
IDFile f(PMString("Macintosh HD:Users:manan:Desktop:demo_script.jsx"));
script.SetFile(f);
ScriptData result;
PMString errorString;            
InterfacePtr<IScriptManager> scriptManager(Utils<IScriptUtils>()->QueryScriptManager(kJavaScriptMgrBoss));
            InterfacePtr<IScriptRunner> scriptRunner(scriptManager, UseDefaultIID());
            Utils<IScriptUtils>()->DispatchScriptRunner( scriptRunner, script,
                                                        arg, result,
                                                        errorString, kTrue);
            PMString retval;
            result.GetPMString(retval);
            CAlert::InformationAlert(retval);

result will be populated by the value that you return from your jsx code, based on its type use the appropriate Get method and you should be good.

 

P.S. :- Have you been able to use DispatchScriptRunner command passing the script as a string, i am not able to do that. If you did please share your code snippet

 

-Manan 

PickoryAuthor
Brainiac
February 3, 2020

Hi Manan,

I am using a file with DispatchScriptRunner.

Your code works! Thank you.

My script was wrong. 

 

It is quite handy that you can set a named parameter from the script.

 

Dirk and Manan, both correct answers.

 

 

Brainiac
February 3, 2020

Anything wrong with "@param result is the return value OUT" ?

PickoryAuthor
Brainiac
February 3, 2020

Hi Dirk, 

 

Thank you. I am not sure how to access or set that from the script. So I have ended up using the passed paramters, like this.

 

Utils<IScriptArgs>()->Set(PMString("Param1"), "DoAction" ); 

Utils<IScriptUtils>()->DispatchScriptRunner ( .......

 

PMString pm;

pm = Utils<IScriptArgs>()->Get(PMString("Param1") );