10 Replies Latest reply on Jan 8, 2018 2:25 PM by Trevorׅ

    Call an ExtendScript Script from the Command Line

    frameexpert Level 4

      Hi! I can call an ExtendScript script from a command line or batch file just by using its path, but is there a way to pass parameters to the script? Thanks. -Rick

        • 1. Re: Call an ExtendScript Script from the Command Line
          Trevorׅ Adobe Community Professional

          Hi Rick

           

          I answered the question over here Re: Create a build script for Extend Script

          I have some more info on it if needed but don't have time to post it this week.

           

          Regards

           

          Trevor

           

           

          page 11 in the user manual

           

          Automatic jsxbin Conversion

          The jsxbin format (Binary JavaScript) enables distributing a script without exposing its source code. The

          ExtendScript ToolKit offers an Export to Binary feature that instantly converts a js(x) file into jsxbin. The

          jsxbin export process can be done automatically without user interaction.

          To do this:

          1. Write a compiler script file that compiles .jsx files into a .jsxbin file.

           The script file must start with this target directive:

          #target estoolkit#dbg

           Use the app.compile() method and pass the content of the script file as a String parameter.

           In the script, store the result in a new file with the extension .jsxbin.

          2. Launch the ExtendScript ToolKit with the command-line parameter -cmd [path to compiler script file]:

          Windows:

          "ExtendScript Toolkit.exe" -cmd compiler.jsx

          Mac:

          "ExtendScript Toolkit.app/Contents/MacOS/ExtendScript Toolkit" \

          -cmd compiler.jsx

          Here is a sample compiler script (compiler.jsx) with the source script's file path hardcoded.

          #target estoolkit#dbg

          var fileIn = File("/c/jsxbin_test/source.jsx");

          fileIn.open("r");

          var s = fileIn.read();

          fileIn.close();

          var t = app.compile(s);

          var fileOut = File( fileIn.absoluteURI + "bin" ) ;

          fileOut.open("w");

          fileOut.write(t);

          • 2. Re: Call an ExtendScript Script from the Command Line
            daitranthanhoa Level 1

            Try this code:

            var path = app.scriptArgs.getValue( "indd_path" );

            cmd:

            sampleclient -host localhost:185 C:\Script\main.jsx indd_path="a.indd"

            • 3. Re: Call an ExtendScript Script from the Command Line
              Trevorׅ Adobe Community Professional

              can you elaborate on  sampleclient -host localhost:185

              • 4. Re: Call an ExtendScript Script from the Command Line
                daitranthanhoa Level 1

                i using indesign server.

                • 5. Re: Call an ExtendScript Script from the Command Line
                  Dirk Becker Level 4

                  sampleclient is used to send a SOAP command to InDesign Server.

                   

                  While this is an old discussion, let me add this command to cover the Mac side with InDesign Desktop:

                   

                  osascript -e 'tell application id "com.adobe.indesign" to do script "alert(arguments.toSource())" language javascript with arguments ["Hello", "World"]'

                   

                  osascript is a shell command to launch an AppleScript.

                  application id "com.adobe.indesign" is a version independent way to address InDesign.

                  • 6. Re: Call an ExtendScript Script from the Command Line
                    Trevorׅ Adobe Community Professional

                    Thanks Dirk

                     

                    From Windows one can use.

                    powershell -command "$ind = new-object -comobject InDesign.Application.CC.2018; $ind.DoScript('PathToFile', 1246973031)"

                    From Mac to run a script File (which can be more convenient) one can use

                    osascript  -e 'tell application "Adobe InDesign CS5" to do script alias "PathToFile" language javascript '''

                    One question I have is at least on Windows are methods or properties available by connecting directly to the com that are not available from the scripting dictionaries. I.e. are any SDK properties available?

                    • 7. Re: Call an ExtendScript Script from the Command Line
                      Dirk Becker Level 4

                      Trevor,

                       

                      The COM interface is described by a "TLB" Type Library. InDesign generates it from the same ScriptInfo resources that it also uses for the AppleScript Terminology, the ExtendScript object model and even for INX and IDML. So in most cases the exposed functionality is the same, with few intentional (extra developer work) differences, e.g. "delete" renamed to "remove" where it collides with a reserved keyword, or properties excluded from a specific engine (not in IDML ...).

                      I'm not aware of any list of actual differences.

                      1 person found this helpful
                      • 8. Re: Call an ExtendScript Script from the Command Line
                        Trevorׅ Adobe Community Professional

                        Hi Dirk,

                         

                        I would like to be able to call a script by targeting the the host apps pid

                        I can tell it to do applescripts but can't tell it to do javascripts

                        Any ideas of how I can do this?

                         

                         

                        tell application "System Events"

                               -- 14883 and 14654 are the PIDs of my running instance of InDesign

                               set proc to item 1 of (processes whose unix id is 14883)

                               --set proc to item 1 of (processes whose unix id is 14654)

                              

                               -- AppleScript works

                               tell application proc to do script "/Applications/Adobe InDesign CC 2018/Scripts/Scripts Panel/Samples/AppleScript/PathEffects.applescript"

                              

                               -- javascript doesn't work doesn't let the language to to set to javascript

                               --tell application proc to do script "/Applications/Adobe InDesign CC 2018/Scripts/Scripts Panel/Samples/JavaScript/PathEffects.jsx" language javascript

                        end tell

                        • 9. Re: Call an ExtendScript Script from the Command Line
                          Dirk Becker Level 4

                          Trevor,

                           

                          "tell application proc" does not work, there is no coercion from process to application.

                          From error messages with jsx attempts I guess that your AppleScript is still executed because the "tell" will end up at that script's object, and inside the script there'll be another tell to target InDesign. It should also fail with your posix path, but why complain?

                           

                          Given that all InDesign versions have the same bundle identifier, I see no way to address a specific one by means of "tell". Unfortunately

                          the Carbon psn seems to be unsupported nowadays, that eliminates other approaches. I'd try to make the process frontmost via System Events, then hope that "tell" prefers that frontmost. Something along

                           

                          tell application "Finder"

                            set jsx to (file "test.jsx" of desktop) as alias

                            set proc to first process whose bundle identifier is "com.adobe.InDesign"

                            set frontmost of proc to true

                            tell application id "com.adobe.InDesign" to do script jsx language javascript

                          end tell

                          1 person found this helpful
                          • 10. Re: Call an ExtendScript Script from the Command Line
                            Trevorׅ Adobe Community Professional

                            Thanks Dirk

                             

                            That's seems to work well.

                            I tested it with multiple simultaneous instances of Indesign and it targets the version that it's called from.

                            My next task it to get it working also on Windows and on the other apps as well.

                            I'll try work on it in the next  month or 2.