5 Replies Latest reply on Jul 7, 2009 7:32 PM by richardh6

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

    richardh6 Level 1

      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. Re: [JS, InDesign CS2] passing parameters from one script to another
          Kasyan Servetsky Level 5

          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

          1 person found this helpful
          • 2. Re: [JS, InDesign CS2] passing parameters from one script to another
            liedzeit Level 2

            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. Re: [JS, InDesign CS2] passing parameters from one script to another
              richardh6 Level 1

              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

              • 4. Re: [JS, InDesign CS2] passing parameters from one script to another
                Dirk Becker  Level 4

                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

                1 person found this helpful
                • 5. Re: [JS, InDesign CS2] passing parameters from one script to another
                  richardh6 Level 1

                  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