3 Replies Latest reply on Apr 12, 2017 3:11 AM by Laubender

    Way to open InDesign and run a specified .jsx script from an external .js script?

    jamest68293015 Level 1

      I'm trying to create a JavaScript script that will do 3 things:

      1) Launch Adobe InDesign

      2) Wait approximately 5-10 sec for my InDesign plugin to load (Theplugin is MPS DesignMergePro for those wondering)

      3) Once the plugin is loaded, run a specified script

       

      I have step 1 accomplished. However, I can't figure out how to accomplish the other 2 steps. Any ideas?

        • 1. Re: Way to open InDesign and run a specified .jsx script from an external .js script?
          Laubender Adobe Community Professional & MVP

          Hi James,

          a moderator of the forums moved your question from the InDesign User forum to the InDesign Scripting forum.

          I hope, that's ok with you.

           

          Back to your question:

          What is your exact version of InDesign on what OS ?

          Is your plugin scriptable?

           

          Three possible solutions I see, but cannot test:

           

          1. Do the script in step 3 as a startup script that will only run, if you do the script in step 1.

          Or do it as startup script without dependency to step 1 if you want to launch it every time InDesign is started by the user.

          My assumption here is, that a startup script has to wait until InDesign is ready to do something.

           

          2. Add an idle task and attach an event listener for "idleEvent" that could show when InDesign is ready.

          See property sleep of idleTasks. E.g.: app.idleTasks.add({sleep : 1000});

           

          3. Try to do something with your plugin by using one of its menu commands with step 3.
          You could perhaps check if a menu command of the plugin is ready. And try again after a certain amount of time if it's not ready…
          Perhaps $.sleep(n) will give the plugin enough time to load. Where n is the number of milliseconds to wait.

           

          Regards,
          Uwe

          • 2. Re: Way to open InDesign and run a specified .jsx script from an external .js script?
            jamest68293015 Level 1

            For clarity, I"m running on Windows 7 with Adobe InDesign CC 2017

             

            Thanks for the suggestions! My main problem is I've never actually done scripting for InDesign prior to this so I'm not very familiar with the syntax for actions within the application. What exactly would the syntax be for step 3? I've been suggested:

             

            app.doScript(pathToScriptFIle ,ScriptLanguage.JAVASCRIPT);

             

            But haven't gotten that to work. Any suggestions?

            • 3. Re: Way to open InDesign and run a specified .jsx script from an external .js script?
              Laubender Adobe Community Professional & MVP

              Hi James,

              are you familiar with the concept of startup-scripts?
              Scripts that are run after InDesign has started?

               

              You'll need a special folder named startup scripts in InDesign's Scripts folder ( for all users ) or one in your user folder where you store the jsx file. InDesign will pick it up after start and executes the script. At that time the plug-in should be loaded. And if not try a $.sleep(10000); statement at the beginning before your actual code should run.

               

              Something like that:

               

              // Save that script in your startup scripts directory!
              
              var before = Date.now();
              
              $.sleep(10000);
              
              var after = Date.now();
              var elapsed = ( after - before ) / 1000 ;
              
              alert( "Ready for action after:"+"\r"+elapsed+" seconds." );
              
              /*
              
                  Your code here:
              
              */
              

               

              If that would work for you we could go on and talk about variables that can be set by one script and read by another one running.
              We'll need that if you want to execute the additional code only if the JavaScript of step 1 is used to start InDesign.

               

              FWIW: Show the code of the JavaScript file that starts up InDesign from your file system.
              Use the forum's Advanced Editing feature to format the code as code with >> Insert > Syntax Highlighting > javascript

               

              Regards,
              Uwe

              1 person found this helpful