Skip to main content
Known Participant
July 6, 2009
Answered

[JS, InDesign CS2] passing parameters from one script to another

  • July 6, 2009
  • 3 replies
  • 2250 views

In CS3, you can pass parameters from one script to another:

app.doScript (myScriptFile, ScriptLanguage.javascript, myParameters);

where myParameters is an array of parameters, and then an array called "arguments" gets created within the script you have called, to hold the local copies of the variables.

As far as I can tell this feature was added in InDesign CS3, and does not exist in InDesign CS2.  The reference manual for CS2 says that app.doScript takes a maximum of 2 arguments:  the name of the script, and the name of the language.  No parameter-array argument.

My question:  Am I wrong about this?  And if I'm right about this, does anyone know of any way to pass parameters from one script to another in InDesign CS2?

Thanks.

- Richard

This topic has been closed for replies.
Correct answer liedzeit

For what it’s worth. I do not pass parameters by script (anymore - mainly because I have too many...). I let script A write a file params.jsx and have a #include params.jsx in script B.

Ralf

3 replies

Inspiring
July 7, 2009

I just ran this in CS2:


=== b.jsx ===

var a = "Hello, world";

var f =File("/Adobe/ID4Rel/Presets/Scripts/a.jsx");
function fromInsideFunction()
{
$.global.b = "Bah!";
}
fromInsideFunction();

app.scriptArgs.set("q","ah!");
app.doScript(f,ScriptLanguage.javascript);

=== a.jsx ===

alert(a);
alert(b);
alert(app.scriptArgs.get("q"));

... and the only problem was to find a browser on that ancient CS2 machine that would not cause hickup of the forum editor.

Edit: removed older version that sneaked in thru the forum editor

richardh6Author
Known Participant
July 8, 2009

Dirk -

Thanks for going back and editing it.  That was a bit confusing before.

Now it's clear as a bell, and very helpful.  I ran it myself, and got all the alerts to work.

So all the scripts are floating in one big happy runtime environment, sharing variables.  Good to know.

To cut down on the confusion when I have to alter the code six months from now, I think I'll stick to using the app.scriptArgs property, even though it's slightly more time-consuming than the other ways.

- Richard

liedzeitCorrect answer
Inspiring
July 7, 2009

For what it’s worth. I do not pass parameters by script (anymore - mainly because I have too many...). I let script A write a file params.jsx and have a #include params.jsx in script B.

Ralf

richardh6Author
Known Participant
July 7, 2009

Thank you both Ralf and Kasyan.

I think I'm going to go with Ralf's method.

I can't use Kasyan's without a slight modification, since I'm passing a file object to the doScript method, not a string.  I'd have to read the whole file in as a string and then concatenate that to my parameter-setting statements before I run the script.  Ralf's method seems slightly easier.

Thanks,

Richard

Kasyan Servetsky
Legend
July 7, 2009

Hi Richard,

You can easily do it by using two sets of quotes: single and double.

Here is an example:

// A simple script without parameters

var myVBScript = 'Set myInDesign = CreateObject(\"InDesign.Application.CS2\")\rMsgBox \"Hey!\"';
app.doScript(myVBScript, ScriptLanguage.visualBasic);

// The same script with one parameter sent

var myMessageFromJS = "Hey! This is a parameter sent from JS.";
var myVBScript = 'Set myInDesign = CreateObject(\"InDesign.Application.CS2\")\rMsgBox\"' + myMessageFromJS + '\"';
app.doScript(myVBScript, ScriptLanguage.visualBasic);

I don't have CS2 any more, so I tested it with CS3.

Kasyan