1 Reply Latest reply on Oct 15, 2012 4:16 AM by domnic.rj23

    Passing arguments to jsx file externally

    Sephirioth

      Hi,

       

      I have a script (javascript, jsx) that will parse content from InDesign (.indd) documents using InDesignServer. I want to be able to pass the filename, as well as the path of the indesign file as parameters to this script.

       

      I have tried this vbs solution:

       

      ==========================

      runjavascript.vbs

      -------------

      Option Explicit

      On Error Resume Next


      Dim appRef

      Dim javaScriptFile


      Set appRef = CreateObject( "Photoshop.Application" )


      appRef.BringToFront


      javaScriptFile = "C:\myscript\test.jsx"


      call appRef.DoJavaScriptFile( javaScriptFile, Array(Array("one","two"), Array("three")), 1)


      ------

      DoJavaScriptFile takes 3 params, the first being the script, the 2nd is an array of params. In my example, you can have an array of arrays of params. When you receive params from javascript side, it will see param 0 as (one, two), param 1 is (three). For most people, simple case is fine: eg:


      call appRef.DoJavaScriptFile( javaScriptFile, Array("one","two", "three"), 1)


      The javascript would look like this:


      test.jsx

      ---------

      #target photoshop


      if (arguments.length > 0)

      alert("ARGUMENT 0 = " + arguments[0]);


      ----

      from the jsx side, there's a magical variable called "arguments" of array type. When you pass variables in, the 1st one will be arguments[0], the next one would be arguments[1], and so forth.


      To execute this from command line, (assuming everything lives in c:\myscript):


      cscript c:\myscript\runjavascript.vbs

       

       

      ==========================

       

      This approach does not work, because I get an error from the CreateObject function, it cannot create an object for InDesignServer.Application.

       

      Ideally, I want to be able to pass arguments from a python script to a jsx script.

       

      Setup:

      InDesign CS4 .indd documents

      Win2k8 server

      JavaScript (via ExtendScript toolkit)

      InDesignServer CS5.5 (32bit)

      SmartLayout plugin