4 Replies Latest reply on Nov 17, 2013 8:06 PM by samFlowse

    How to open selected files from a listbox

    samFlowse

      I am trying to open files from selected items in a listbox, but am having some problems.

       

      Here is my code:

      var firstLibrary = "C:\\Program Files (x86)\\Adobe\\test\\Library1.indl";

      var secondLibrary = "C:\\Program Files (x86)\\Adobe\\test\\Library2.indl";

       

      var libraryList = [firstLibrary, secondLibrary]; // array filled with file url's

       

      var w = new Window ("dialog");

      var myList = w.add ("listbox", undefined, libraryList, {multiselect: true}); // list populated with libraryList array

      var print = w.add ("button", undefined, "Print selected items");

       

      myList.selection = 0; // default selection of first index

       

      print.onClick = function () // when button is clicked, should print selections to console, open files and then close the window

          {

          for (var i = 0; i < myList.selection.length; i++){

              $.writeln (myList.selection[i].text); // <-- correctly prints the selected items to the console

              //app.open(File(myList.selection[i].text)); // <-- this line I would assume allows me to open the files because the text is a file url,

                                                                              // however, uncommenting it breaks the code

          }

          w.close();

      }

       

      w.show ();