8 Replies Latest reply on Jun 16, 2011 7:59 PM by John Hawkinson

    How to launch a script using a script

    RichardM0701

      Hi,

       

      I am working on a User Interface that will act as a dashboard to launch scripts or tools. I want to link my buttons to the scripts I have. I have heard about "doscript", but not sure how to use it. Can any one help? One of the scripts that im trying to launch is "Fix Broken Links.jsx".

       

      BTW (I'm new to Java programming so please be patient with my messy code!)

      Window Capture.png

       

       

      var w = new Window ("palette");
          w.alignChildren = ["fill","fill"];
          w.graphics.backgroundColor = w.graphics.newBrush (w.graphics.BrushType.SOLID_COLOR, [0.8, 0.8, 0.8]);
         
          var myInstructGroup1 = w.add ("group"); 
             myInstructGroup1.add ("statictext", undefined, "Tech Pubs Indesign Toolbox");
          //this is the overall layout
          var g1 = w.add ("group");
              g1.alignChildren = ["left","fill"];
          //panel 1   
          var p1 = g1.add ("panel");
              p1.preferredSize = [500, 300]; // Use [100,100] to get the second scr. shot
              g1.separator = g1.add ("panel"); // This shows as a vertical line
              p1.orientation = "column";
              p1.alignChildren = "left";
             
             
              //text for panel 1
              var myInstructGroup3 = p1.add ("group"); 
                  myInstructGroup3.add ("statictext", undefined, "Authoring Tools");
                 
                 
              var myLaunch1 = p1.add ("group");
                  myLaunch1.orientation = "row";
                  myLaunch1.alignChildren = "left";
             
                  var f = File ("H:\Datasource.jpg")
                      myLaunch1.add ("iconbutton", undefined, f );
                      myLaunch1.add ("statictext", undefined, "Launch STE Checker");
                 
                  var g = File ("H:\Datasource.jpg")
                      myLaunch1.add ("iconbutton", undefined, f );
                      myLaunch1.add ("statictext", undefined, "Insert a Figure");

       

                  var h = File ("H:\Datasource.jpg")
                      myLaunch1.add ("iconbutton", undefined, f );
                      myLaunch1.add ("statictext", undefined, "Fraction Maker");
                        
                  var i = File ("H:\Datasource.jpg")
                      myLaunch1.add ("iconbutton", undefined, i );
                      myLaunch1.add ("statictext", undefined, "Update All TOC's");
                     
          var myLaunch2 = p1.add ("group");
          myLaunch2.orientation = "row";
          myLaunch2.alignChildren = "left";
                 
                  var j = File ("H:\picture.jpg")
                      myLaunch2.add ("iconbutton", undefined, j );
                      myLaunch2.add ("statictext", undefined, "Relink Images");
             
      // This is the line's width
              g1.separator.minimumSize.width = g1.separator.maximumSize.width = 3;
             
          var p2 = g1.add ("panel");
              p2.preferredSize = [500, 300];
              w.separator = w.add ("panel"); // This one shows as a horizontal line
              p2.orientation = "column";
              p2.alignChildren = "left";
             
              var myInstructGroup4 = p2.add ("group"); 
                  myInstructGroup4.add ("statictext", undefined, "Desktop Publishing Tools (DTP)");

       

              var myLaunch2 = p2.add ("group");
                  myLaunch1.orientation = "row";
                  myLaunch1.alignChildren = "left";
             
              var f1 = File ("H:\pdf.jpg")
                  myLaunch2.add ("iconbutton", undefined, f1 );
                  myLaunch2.add ("statictext", undefined, "PDF Maker");

       

       

       

       

       


      // It says "height", but is again the line's width!
              w.separator.minimumSize.height = w.separator.maximumSize.height = 3;
             
          var g2 = w.add ("group");
              g2.alignChildren = ["fill","fill"];
             
          var p3 = g2.add ("panel");
              p3.preferredSize = [500, 300]; // Use [200,50] to get the second scr. shot
              g2.separator = g2.add ("panel"); // This shows as vertical a line
              g2.separator.minimumSize.width = g2.separator.maximumSize.width = 3;
              p3.orientation = "column";
              p3.alignChildren = "left";
             
              var myInstructGroup5 = p3.add ("group"); 
                  myInstructGroup5.add ("statictext", undefined, "Translation Prewash Tools");

       

              var myLaunch3 = p3.add ("group");
                  myLaunch1.orientation = "row";
                  myLaunch1.alignChildren = "left";
             
              var myPic1 = File ("H:\picture.jpg")
                  myLaunch3.add ("iconbutton", undefined, myPic1 );
                  myLaunch3.add ("statictext", undefined, "Check for Items on Pasteboard");
                 
                 
          var p4 = g2.add ("panel");
              p4.preferredSize = [500, 300];
              g2.separator = g2.add ("panel"); // This shows as vertical a line
              g2.separator.minimumSize.width = g2.separator.maximumSize.width = 3;
              p4.orientation = "column";
              p4.alignChildren = "left";
             
                var myInstructGroup5 = p4.add ("group"); 
                  myInstructGroup5.add ("statictext", undefined, "Misc Informaiton and Tools");
             
              w.show ();

        • 1. Re: How to launch a script using a script
          John Hawkinson Level 5
          BTW (I'm new to Java programming so please be patient with my messy code!)

          Javascript is not Java! There are some superficial similarities but they're really not that similar at all.

          Anyhow, it doesn't look like we need to look at your code to answer your question?

           

          [ Also, please click the >> and select Java Syntax Highlighting when posting code. Yes, ironically you're posting Javascript, but the forum doesn't know that and they colorize the same. ]

           

          I am working on a User Interface that will act as a dashboard to launch scripts or tools. I want to link my buttons to the scripts I have. I have heard about "doscript", but not sure how to use it. Can any one help? One of the scripts that im trying to launch is "Fix Broken Links.jsx".

          app.doScript(new File("Fix Broken Links.jsx"));

          1 person found this helpful
          • 2. Re: How to launch a script using a script
            RichardM0701 Level 1

             

            Thank you John, I appreciate your insight and guidance on posting as well. Let me give this a shot and see what happens.

            • 3. Re: How to launch a script using a script
              RichardM0701 Level 1

              Hi John,

               

              What am I doing wrong here? I tried it using the function and no luck as well. Im sure im doing something wrong in the syntax.

               

              myRelink_button.onClick = function (app.doScript(new File("Fix Broken Links.jsx";
              

               

               

              var j = File ("H:\picture.jpg")
                   var myRelink_button = myLaunch2.add ("iconbutton", undefined, j );
                   myLaunch2.add ("statictext", undefined, "Relink Images");
                   myRelink_button.onClick = app.doScript(new File("Fix Broken Links.jsx"));
              
              • 4. Re: How to launch a script using a script
                Muppet Mark Level 5

                Your callback should be a function… Not tested but…

                 

                myRelink_button.onClick = function()  { app.doScript(new File("Fix Broken Links.jsx")); }
                

                1 person found this helpful
                • 5. Re: How to launch a script using a script
                  RichardM0701 Level 1

                  Thanks, I will give this a try.

                  • 6. Re: How to launch a script using a script
                    John Hawkinson Level 5
                    What am I doing wrong here? I tried it using the function and no luck as well. Im sure im doing something wrong in the syntax.

                    One definitely problem is you've told us "no luck" but haven't told us anything further!

                    If it were a syntax error, you'd probably get an error.

                    Otherwise, it's probably an error of semantics, not syntax.

                     

                    But you really must tell us what happened in order for us to give good advice!

                    (Even if the answer is "nothing happened" in which case you should try to instrument your program with some simple $.writeln("whatever") or alert("wahtever")s in order to get a clue what is going wrong.)

                    • 7. Re: How to launch a script using a script
                      RichardM0701 Level 1

                      Thanks John for helping me hone in on how to use this forum. This is valuable information and input so thanks for leading me in the right direction.

                      As for the code, I have taken the input you guys provided and simplified it quite a bit to help troubleshoot the issue.

                       

                      Here is my new code:

                      var myWindow = new Window ("dialog");
                      var myMessage = myWindow.add ("statictext");
                      myMessage.text = "Fluke TechPubs Tools";
                      
                      var myButtonGroup = myWindow.add ("panel");
                          myButtonGroup.alignment = "left";
                          myButtonGroup.add ("statictext", undefined, "Authoring Tools");
                          var STELaunch =  myButtonGroup.add("button", undefined, "STE TOOL");
                          STELaunch.onClick = function()  { app.doScript(new File("Fix Broken Links.jsx")); }
                          
                      myWindow.show ( );
                      

                       

                      Region Capture2.png

                       

                      What is happening: I run the code by pressing the button and I do not get any errors nor any response to let me know that it is trying to run. The desired script does not launch either. I have taken a screenshot of how I have my scripts laid out in the directory. In the code above, I am not sure what "new file" in the app.doSript line is or does. Could that be where its missing?

                       

                       

                       

                      Region Capture.png

                      • 8. Re: How to launch a script using a script
                        John Hawkinson Level 5

                        What is happening: I run the code by pressing the button and I do not get any errors nor any response to let me know that it is trying to run.

                        When I run your script from the ESTK, I get an orange bar on line 9 and at the bottom of the ESTK window it reports,

                        "THe file Machine:Applications:Adobe InDesign CS5:Scripts:XHTML For Digital Editions:Fix Broken Links.jsx was not found."

                         

                        Which is expected since I have no such script. If the path isn't being searched properly you might want to specify a path to the script, or other trickery.

                         

                        But of course, you followed my advice from above, right?:

                         

                        if the answer is "nothing happened" in which case you should try to instrument your program with some simple $.writeln("whatever") or alert("wahtever")s in order to get a clue what is going wrong.

                         

                        So what happened? Is your onclick handler running or is it not?

                        In the code above, I am not sure what "new file" in the app.doSript line is or does. Could that be where its missing?

                        It constructs a File object from the provided path. Have you read the Javascript Tools Guide CS5?