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

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

Community Beginner ,
Jul 06, 2009 Jul 06, 2009

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

TOPICS
Scripting
2.1K
Translate
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

Contributor , Jul 07, 2009 Jul 07, 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

Translate
Valorous Hero ,
Jul 07, 2009 Jul 07, 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

Translate
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
Contributor ,
Jul 07, 2009 Jul 07, 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

Translate
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
Community Beginner ,
Jul 07, 2009 Jul 07, 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

Translate
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
Advocate ,
Jul 07, 2009 Jul 07, 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

Translate
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
Community Beginner ,
Jul 07, 2009 Jul 07, 2009
LATEST

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

Translate
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