20 Replies Latest reply on Aug 17, 2017 1:55 AM by Trevorׅ

    Create a build script for Extend Script

    mdegamo Level 1

      I have several scripts I want exported as binary via "File > Export as Binary" in ExtendScript Toolkit. I want to be able to call ESTK via shell script and tell it to compile that certain file.

        • 1. Re: Create a build script for Extend Script
          Trevorׅ Adobe Community Professional

          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);

          1 person found this helpful
          • 2. Re: Create a build script for Extend Script
            mdegamo Level 1

            When my scripts contains new line, app.compile() doesn't return anything.

            • 3. Re: Create a build script for Extend Script
              mdegamo Level 1

              It's the #include directive the fails it from compiling.

              • 4. Re: Create a build script for Extend Script
                mdegamo Level 1

                Finally got it to work, using this:


                app.compile(s, undefined, fileIn.parent.absoluteURI);

                 

                The third argument sets the includePath of the current script which resolves the relative import.

                2 people found this helpful
                • 5. Re: Create a build script for Extend Script
                  Trevorׅ Adobe Community Professional

                  Glad you got it

                   

                  If you need  to deal with #targetengine session or the like then you could do a regex on s (the read file) and remove the targetengine line and then enclose the jsx in a doScript preceded by the #targetengine

                   

                  • Check if file has targetengine
                  • if yes remove it
                  • compile new string to export file b
                  • write new jsx file  #targetengine foo  + app.doScript( + read b + )

                   

                  Trevor

                   

                  BTW Bob Stucky has a script for batch binaries, search the forum or his site for it

                  • 6. Re: Create a build script for Extend Script
                    Trevorׅ Adobe Community Professional

                    Hi Mark

                     

                    I'm very interested where did you find out the arguments of compile?

                     

                    Thanks

                     

                    Trevor

                    • 7. Re: Create a build script for Extend Script
                      mdegamo Level 1

                      Hi Trevor,

                       

                      I found it implemented on line 2450 on this script "C:\Program Files\Adobe\Adobe Utilities - CS6\ExtendScript Toolkit CS6\Required\80document.jsx".

                       

                      Thanks,

                      Mark

                      • 8. Re: Create a build script for Extend Script
                        Trevorׅ Adobe Community Professional

                        Well spotted!

                         

                        Thanks

                        • 9. Re: Create a build script for Extend Script
                          Laubender Adobe Community Professional & MVP

                          Ah!
                          On Mac OSX its in the "Required" folder of the "SharedSupport" folder of the app package of the ESTK app one can reveal by "Open Package" with a right click on the app:

                           

                          RequiredESTKpackageContents.png

                           

                          @Mark Anthony – thank you for sharing this!

                          Uwe

                          • 10. Re: Create a build script for Extend Script
                            TᴀW Adobe Community Professional & MVP

                            What are all those jsx files??

                            • 11. Re: Create a build script for Extend Script
                              Laubender Adobe Community Professional & MVP

                              @Ariel – They represent and control the inner workings of the ESTK and could reveal a lot of undocumented features. I think, Dirk Becker mentioned some of the possibilities to script the ESTK by looking into these files. Bob Stucky as well. There is a lot to detect here. :-)


                              See Dirk Becker's notes on the ESTK here:

                              ExtendScript Toolkit

                               

                              Uwe

                              • 12. Re: Create a build script for Extend Script
                                TᴀW Adobe Community Professional & MVP

                                Nice! I take it that the UI of ESTK is NOT ScriptUI, though, right? I

                                think it's Flash-based, IIRC.

                                • 13. Re: Create a build script for Extend Script
                                  Trevorׅ Adobe Community Professional

                                  I'm pretty sure it's flash based I tried in the past unsuccessfully to make some changes to the UI.

                                  Peter brings down 35omvUI.jsx in his SUI guide

                                  I have never seen any normal documentation on scripting the ESTK.  I now mainly use sublime text which is way way better and made a build to execute the scripts from there through the ESTK

                                  • 14. Re: Create a build script for Extend Script
                                    Trevorׅ Adobe Community Professional

                                    Hi Uwe,

                                     

                                    Thanks for the link to Dirk's site.  There's some very good stuff there (not just on this topic).

                                    I just posted Dirk a mail asking if he knows of where to get documentation of the properties and methods of scripting the ESTK

                                     

                                    Trevor

                                    • 15. Re: Create a build script for Extend Script
                                      jazzyman02 Level 1

                                      Hi Trevor!

                                       

                                      I don't understand...

                                       

                                      • Check if file has targetengine
                                      • if yes remove it
                                      • compile new string to export file b
                                      • write new jsx file  #targetengine foo  + app.doScript( + read b + )

                                       

                                      Please Someting to detail....

                                      • 16. Re: Create a build script for Extend Script
                                        Trevorׅ Adobe Community Professional

                                        Not sure what your not clear about.

                                        But here goes again.

                                        Let's say we have our jsx script

                                        #target indesign-12
                                        #targetengine test
                                        alert('$.fileName: ' + $.fileName + '\n$.engineName: ' + $.engineName + '\napp.name:' + app.name);
                                        

                                         

                                        We save it in ~/Documents/Adobe%20Scripts/Scripts%20Panel/Forum%20Scripts/targetEngineTest.jsx

                                         

                                        We then write and save the below file and then execute it.

                                         

                                        #target estoolkit#dbg
                                        
                                        var jsxFile, jsxBinFile, jsxScript, jsxbinString;
                                        
                                        jsxFile = new File('~/Documents/Adobe%20Scripts/Scripts%20Panel/Forum%20Scripts/targetEngineTest.jsx');
                                        jsxBinFile = new File( jsxFile.absoluteURI + 'bin' ) ;
                                        jsxFile.open('r');
                                        jsxBinFile.open('w');
                                        
                                        jsxScript = jsxFile.read();
                                        jsxbinString = app.compile(jsxScript);
                                        
                                        jsxBinFile.write(jsxbinString);
                                        
                                        jsxFile.close();
                                        jsxBinFile.close();
                                        

                                         

                                        We then run the jsxbin file (You can just copy and paste the below the line breaks aren't important)

                                         

                                        @JSXBIN@ES@2.0@MyBbyBn0ABJCnAEjzFjBjMjFjSjUBfRBCzBhLCCCCCCCCCnXzIjGjJjMjFiOjBjNj
                                        FDfjzBhEEfeMhEhOjGjJjMjFiOjBjNjFhahAnnnePKhEhOjFjOjHjJjOjFiOjBjNjFhahAXzKjFjOjH
                                        jJjOjFiOjBjNjFFfjEfnnnneKKjBjQjQhOjOjBjNjFhaXzEjOjBjNjFGfjzDjBjQjQHfnnff0DzAIBy
                                        B
                                        

                                         

                                        If we run the jsxbin from for example the ExtendedScript CC Toolkit engine we would still expect the script to be executed by InDesign, that's what the #target is supposed to do, also we would expect the "test" target engine to be created.

                                        But it's not

                                         

                                        2017-08-16_15-45-36.png

                                         

                                        If we run the regular jsx script from the ExtendedScript CC Toolkit engine we get what we expect

                                         

                                        2017-08-16_15-52-30.png

                                        The reason is simple.

                                        Let's rewrite the jsx script missing out the #target and #targetengine lines

                                         

                                        alert('$.fileName: ' + $.fileName + '\n$.engineName: ' + $.engineName + '\napp.name:' + app.name)
                                        

                                         

                                        The result is almost identical

                                        @JSXBIN@ES@2.0@MyBbyBn0ABJAnAEjzFjBjMjFjSjUBfRBCzBhLCCCCCCCCCnXzIjGjJjMjFiOjBjNj
                                        FDfjzBhEEfeMhEhOjGjJjMjFiOjBjNjFhahAnnnePKhEhOjFjOjHjJjOjFiOjBjNjFhahAXzKjFjOjH
                                        jJjOjFiOjBjNjFFfjEfnnnneKKjBjQjQhOjOjBjNjFhaXzEjOjBjNjFGfjzDjBjQjQHfnnff0DzAIBy
                                        B
                                        

                                         

                                        There's just one character change. That's shows you the the app.compile just ignores the # lines.

                                        So this is the fix I was suggesting.

                                         

                                        #target estoolkit#dbg
                                        
                                        var jsxFile, jsxBinFile, jsxScript, jsxbinString;
                                        var targetReg, targetEngineReg, wrapper, target, targetEngine;
                                        targetReg = /#target [^\r\n]+/;
                                        targetEngineReg = /#targetengine [^\r\n]+/;
                                        jsxFile = new File('~/Documents/Adobe%20Scripts/Scripts%20Panel/Forum%20Scripts/targetEngineTest.jsx');
                                        jsxBinFile = new File(jsxFile.absoluteURI + 'bin');
                                        jsxFile.open('r');
                                        jsxBinFile.open('w');
                                        jsxFile.encoding = 'UTF8';
                                        jsxBinFile.encoding = 'UTF8';
                                        
                                        jsxScript = jsxFile.read();
                                        jsxbinString = app.compile(jsxScript);
                                        
                                        target = jsxScript.match(targetReg);
                                        targetEngine = jsxScript.match(targetEngineReg);
                                        if (target || targetEngine) {
                                            if (target) {
                                                wrapper = target + '\n';
                                            }
                                            if (targetEngine) {
                                                wrapper += targetEngine + '\n';
                                            }
                                            jsxbinString = wrapper + 'app.doScript("myScript");'.replace(/myScript/, jsxbinString.replace(/[\n\r]/g,'')); 
                                        }
                                        
                                        
                                        
                                        jsxBinFile.write(jsxbinString);
                                        
                                        jsxFile.close();
                                        jsxBinFile.close();
                                        

                                         

                                        This will save the file as

                                        #target indesign-12
                                        #targetengine test
                                        app.doScript("@JSXBIN@ES@2.0@MyBbyBn0ABJCnAEjzFjBjMjFjSjUBfRBCzBhLCCCCCCCCCnXzIjGjJjMjFiOjBjNjFDfjzBhEEfeMhEhOjGjJjMjFiOjBjNjFhahAnnnePKhEhOjFjOjHjJjOjFiOjBjNjFhahAXzKjFjOjHjJjOjFiOjBjNjFFfjEfnnnneKKjBjQjQhOjOjBjNjFhaXzEjOjBjNjFGfjzDjBjQjQHfnnff0DzAIByB");
                                        

                                         

                                        It will then run correctly.

                                         

                                        There's a few downsides, most significantly that not all the apps can run the JSXBIN using app.doScript but in an InDesign forum that will pass.

                                         

                                        HTH

                                         

                                        Trevor

                                        1 person found this helpful
                                        • 17. Re: Create a build script for Extend Script
                                          jazzyman02 Level 1

                                          Ohh~~! Thank you very much. Trevor!

                                          • 18. Re: Create a build script for Extend Script
                                            jazzyman02 Level 1

                                            Hi Trevor!

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

                                            #target estoolkit#dbg 

                                             

                                            var jsxFile, jsxBinFile, jsxScript, jsxbinString; 

                                             

                                            jsxFile = new File('~/Documents/Adobe%20Scripts/Scripts%20Panel/Forum%20Scripts/targetEngineTest.jsx'); 

                                            jsxBinFile = new File( jsxFile.absoluteURI + 'bin' ) ; 

                                            jsxFile.open('r'); 

                                            jsxBinFile.open('w'); 

                                             

                                            jsxScript = jsxFile.read(); 

                                            jsxbinString = app.compile(jsxScript); 

                                             

                                            jsxBinFile.write(jsxbinString); 

                                             

                                            jsxFile.close(); 

                                            jsxBinFile.close();

                                             

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

                                             

                                            your code very well run!

                                            Extend Script Toolkit CC application inside.

                                             

                                            But!

                                            I want to excute your code. automatically.

                                            with other indesign script.

                                            without excute Extend Script Toolkit application and run action.

                                             

                                            How to this work?

                                             

                                             

                                             

                                            • 19. Re: Create a build script for Extend Script
                                              Laubender Adobe Community Professional & MVP

                                              You mean, that you want to do a jsxbin file without using the ESTK?
                                              I don't think that's possible…

                                               

                                              Regards,
                                              Uwe

                                              • 20. Re: Create a build script for Extend Script
                                                Trevorׅ Adobe Community Professional

                                                Read the annotations!!

                                                The normal way of doing this would be stait from terminal or cmd, below is a wrapper

                                                 

                                                //////////////////////////////////////////////////////////////
                                                // For compiling jsxbin from an InDesign Script             //
                                                // You MUST have the ESTK CLOSED!!! (always good advise ;-) //
                                                // You must run the script from InDesign                    //
                                                // By Trevor http://creative-scripts.com                    //
                                                // For Mac and Windows                                      //
                                                //////////////////////////////////////////////////////////////
                                                
                                                // change to address of your favorite scripts
                                                compileJSX('~/Documents/Adobe%20Scripts/Scripts%20Panel/Forum%20Scripts/targetEngineTest.jsx');
                                                
                                                function compileJSX(jsxFile) {
                                                    var compileScript, tempFile, isMac, script;
                                                    isMac = +($.os[0] === 'M');
                                                    compileScript = [
                                                        "#target estoolkit#dbg",
                                                        "var jsxFile, jsxBinFile, jsxScript, jsxbinString;",
                                                        "var targetReg, targetEngineReg, wrapper, target, targetEngine;",
                                                        "targetReg = /#target [^\\r\\n]+/;",
                                                        "targetEngineReg = /#targetengine [^\\r\\n]+/;",
                                                        "jsxFile = new File('__FILE__');",
                                                        "jsxBinFile = new File(jsxFile.absoluteURI + 'bin');",
                                                        "jsxFile.open('r');",
                                                        "jsxBinFile.open('w');",
                                                        "jsxFile.encoding = 'UTF8';",
                                                        "jsxBinFile.encoding = 'UTF8';",
                                                        "jsxScript = jsxFile.read();",
                                                        "jsxbinString = app.compile(jsxScript);",
                                                        "target = jsxScript.match(targetReg);",
                                                        "targetEngine = jsxScript.match(targetEngineReg);",
                                                        "if (target || targetEngine) {",
                                                        "if (target) {",
                                                        "wrapper = target + '\\n';",
                                                        "}",
                                                        "if (targetEngine) {",
                                                        "wrapper += targetEngine + '\\n';",
                                                        "}",
                                                        "jsxbinString = wrapper + 'app.doScript(\"myScript\");'.replace(/myScript/, jsxbinString.replace(/[\\n\\r]/g, ''));",
                                                        "}",
                                                        "jsxBinFile.write(jsxbinString);",
                                                        "jsxFile.close();",
                                                        "jsxBinFile.close();",
                                                        "jsxBinFile.parent.execute();",
                                                    ].join('\n').replace(/__FILE__/, jsxFile);
                                                    tempFile = new File(Folder.temp + '/compileJSX_' + (+new Date()) + '.jsx');
                                                    tempFile.open('w');
                                                    tempFile.write(compileScript);
                                                    tempFile.close();
                                                    script = localize(
                                                        isMac ?
                                                        'do shell script "\\"/Applications/Adobe ExtendScript Toolkit CC/ExtendScript Toolkit.app/Contents/MacOS/ExtendScript Toolkit\\" -cmd \\"%1\\""' :
                                                        'CreateObject("WScript.Shell").Run(\"\"\"C:\\Program Files (x86)\\Adobe\\Adobe ExtendScript Toolkit CC\\ExtendScript Toolkit.exe"" -cmd ""%1\"\"\")',
                                                        tempFile.fsName
                                                    );
                                                    try {
                                                        app.doScript(script, ScriptLanguage[["VISUAL_BASIC", "APPLESCRIPT_LANGUAGE"][isMac]]);
                                                        return script;
                                                    } catch (e){
                                                        return e + '\n' + script;
                                                    }
                                                }