9 Replies Latest reply on Jul 13, 2016 6:41 AM by cbishop01

    Listbox question

    cbishop01 Level 2

      Is it possible to Run a different script from a listbox?  I have a listbox that will have a list of several different Scripts (Most used scripts). and when the scripts are selected from the list i want them to Run. 

       

       var Pan1=w.tabs[0].add ('panel {text: "!! USEFULL SCRIPTS !!", preferredSize: [-1, 200],orientation: "column",alignChildren: ["left","Center"]}');
              mL = Pan1.add("listbox", ["0", "0", "600", "600"]);
          with (mL){
            for (var i = 0; i < 1; i++)  
              mL.add ("item", "Text Auto FIT" ) // Run this script and the one below. etc...
              mL.add ("item", "Crop Marks");
            
              mL.revealItem (mL.items.length - i/1);  
          Pan1.show ()  
          }
      

      Screen Shot 2016-07-01 at 1.47.07 PM.png

        • 1. Re: Listbox question
          tpk1982 Level 4

          Yes possible..use selectedIndex and with that selection use #include <script.jsx> or #includepath<your script path>

          • 2. Re: Listbox question
            Stefan Rakete Level 2

            Here is a sample to see if it would work with app.doScript:

             

            var w = new Window ('dialog {text: "Script List", properties: {closeButton: false}}');

            var Pan1 = w.add ('panel {alignChildren: "left"}');

            mL = Pan1.add("listbox", ["0", "0", "600", "600"]); 

             

            with (mL) {

               

                     for (var i = 0; i < 1; i++)   

                       

                      var listItem1 = mL.add ("item", "Text Auto FIT" ) // Run this script and the one below. etc... 

                      var listItem2 = mL.add ("item", "Crop Marks");      

                     mL.revealItem (mL.items.length - i/1);   

                   

            mL.onClick = function() {

                var curSelection = this.selection.index;

                //alert ( "You clicked item: "  + this.selection.index );

                switch (curSelection) {

                  case 0:

                    app.doScript(script1);

                    break;

                  case 1:

                    app.doScript(script2);

                    break;

                }

               

            }

             

            w.show ();

             

            function script1() { 

                    alert ("run Text Auto FIT.jsx");

            }

             

            function script2() {

                    alert ("run Crop Marks.jsx");

            }

            1 person found this helpful
            • 3. Re: Listbox question
              cbishop01 Level 2

              Sorry it took so long to get back to you.  I was on vacation.  This does not work for me.

              • 4. Re: Listbox question
                Stefan Rakete Level 2

                Hi cbishop01,

                 

                for CC change this line:

                 

                //mL.onClick = function() {

                 

                mL.onChange = function() {

                 

                Thanks Stefan

                1 person found this helpful
                • 5. Re: Listbox question
                  cbishop01 Level 2

                  That worked.  Thank you.. 

                  • 6. Re: Listbox question
                    cbishop01 Level 2

                    Do i add the selectedIndex in the function(){ area?  THe alerts are working but i cannot figure out how to get the scripts to run.  Does it matter if its a dialog or pallet?  Right now its a dialog window.

                    • 7. Re: Listbox question
                      cbishop01 Level 2

                      I've added the below to the Script and it will not run a script from the Listbox.

                       case 0:
                                  app.doScript(CM);
                                  break;
                      

                       

                         function script1() { 
                          var CM = File ( "/Applications/Adobe InDesign CC 2015/Scripts/Scripts Panel/Samples/JavaScript/Came with Indesign/CropMarks.jsx" ).execute();
                         
                          //  alert ("run Text Auto FIT.jsx");
                        }
                      

                      Any ideas? 

                      • 8. Re: Listbox question
                        tpk1982 Level 4

                        I think you need to call function name

                         

                        1. case 0
                        2. app.doScript(script1);  // not CM
                        3. break;
                        1 person found this helpful
                        • 9. Re: Listbox question
                          cbishop01 Level 2

                          Ok i am finding that the .execute(); is actually not what i want that opens the .jsx file i am wanting to open(CropMarks.jsx) in a text editor. It's either from the .execute() or from the "File()". The add.doScript(Script1) did solve the problem of the script not working at all though.  Thank you.  And when it does try to work it wont because my dialog wont close.  So i've tried the below and it will not close or run

                           

                          function script1() { 
                              app.doScript( "/Applications/Adobe InDesign CC 2015/Scripts/Scripts Panel/Samples/JavaScript/Came with Indesign/CropMarks.jsx" ).execute();
                               
                          
                          }
                          $.close();
                          

                          Again if i use file() it opens the file in Dreamweaver. So thats why i tried the app.doScript instead.