Copy link to clipboard
Copied
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
1 Correct answer
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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

