Copy link to clipboard
Copied
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.
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<IScriptU
...
Copy link to clipboard
Copied
Anything wrong with "@param result is the return value OUT" ?
Copy link to clipboard
Copied
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") );
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.