Skip navigation
schiuma24
Currently Being Moderated

Drop Down for opening libraries

Jul 1, 2010 8:52 AM

Im a complete noob at javascript...ive been reading some tutorials and stuff..but its not enough!

what im trying to accomplish here is to have a drop down menu for opening the selected file.

 

 

var myDialog = app.dialogs.add({name:"Iconos Travelplan", canCancel:true});
with(myDialog){
with(dialogColumns.add()){
with(borderPanels.add()){
with(dialogColumns.add()){
staticTexts.add({staticLabel:"Selecciona una biblioteca:"});
}
with(dialogColumns.add()){
var myIcons = dropdowns.add({stringList:
["Iberrail","Costas","Teletipos"], selectedIndex:0});
if(myDialog.show() == true){
var Iberrail = app.open(File("/c/iberrail.indl"), false);
var Costas = app.open(File("/c/costas.indl"), false);
var Teletipos = app.open(File("/c/teletipos.indl"), false);
}
}
}
}
}
myDialog.destroy();

 
Replies
  • Currently Being Moderated
    Jul 1, 2010 12:38 PM   in reply to schiuma24

    Hey!

     

    Here is my solution. Maybe there is some other ways too..

     

    var myFiles = Array(
         ["Iberrail","Costas","Teletipos"], // names in list box
         ["/c/iberrail.indl","/c/costas.indl","/c/teletipos.indl"] // file names
         );
     
    var myDialog = app.dialogs.add({name:"Iconos Travelplan", canCancel:true});
         with(myDialog){
              with(dialogColumns.add()){
                   with(borderPanels.add()){
                        with(dialogColumns.add()){
                             staticTexts.add({staticLabel:"Selecciona una biblioteca:"});
                        }
                        with(dialogColumns.add()){
                             var myIcons = dropdowns.add({stringList:myFiles[0], selectedIndex:0});
                        }
                   }
              }
         }
     
    if(myDialog.show() == true){
         app.open(File(myFiles[1][myIcons.selectedIndex]),false);
    }
     
    myDialog.destroy();
    

     

    tomaxxi

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 2, 2010 2:59 PM   in reply to schiuma24

    You are welcome!

     

    tomaxxi

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 2, 2010 3:29 PM   in reply to schiuma24

    Hey!

     

    It's me again I've got good idea how to make it more user friendly...

    You just have to insert path where you have your libraries,

    and script will automatically fill drop down box with filenames.

     

    You can adjust labels to your wish,

    and you can show/hide working folder in dialog too.

     

    var myWorkFolder = Folder("/d/!myWork"); // working folder
    var showWorkFolder = Boolean(true); // shows(true)/hides(false) working folder in dialog
     
    var strWinTitle = String("Library opener");
    var strWorkFolder = String("Working folder:");
    var strSelectLib = String("Select library:");
    var strNoFiles = String("-- No libraries found --"); // shows if no libraries found
     
    ///////////////////////// SCRIPT /////////////////////////
     
    var myFiles = myWorkFolder.getFiles("*.indl");
    var myFilesNo = myFiles.length;
    var myLibFiles = Array();
     
    if(!myFilesNo){
         myLibFiles[0] = strNoFiles;
    }else{
         for(var i=0; i < myFilesNo; i++){
              myLibFiles.push(myFiles[i].displayName.substr(0,myFiles[i].displayName.lastIndexOf(".")));
         }
    }
     
    var myDialog = app.dialogs.add({name:strWinTitle, canCancel:true});
         with(myDialog){
              with(dialogColumns.add()){
                   if(showWorkFolder){
                        with(dialogRows.add()){
                             with(borderPanels.add()){
                                  with(dialogColumns.add()){
                                       staticTexts.add({staticLabel:strWorkFolder});
                                  }
                                  with(dialogColumns.add()){
                                       staticTexts.add({staticLabel:myPath.fsName});
                                  }
                             }
                        }
                   }
                   with(dialogRows.add()){
                        with(borderPanels.add()){
                             with(dialogColumns.add()){
                                  staticTexts.add({staticLabel:strSelectLib});
                             }
                             with(dialogColumns.add()){
                                  var myLib = dropdowns.add({stringList:myLibFiles, selectedIndex:0});
                             }
                        }
                   }
              }
         }
     
    if(myDialog.show() == true){
         if(myFilesNo){
              app.open(File(myFiles[myLib.selectedIndex]),false);
         }
    }
     
    myDialog.destroy();
    

     

    tomaxxi

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 3, 2010 1:24 AM   in reply to Marijan Tompa

    Tomaxxi,

     

    I think

    staticTexts.add({staticLabel:myPath.fsName});

    should be

    staticTexts.add({staticLabel:myWorkFolder.fsName});

     

    Kasyan

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 3, 2010 1:40 AM   in reply to Kasyan Servetsky

    Hey Kasyan!

     

    Thanks for your reply!

    I forgot to change that after variable name change!

     

    So, here is corrected script:

     

    var myWorkFolder = Folder("/d/!myWork"); // working folder
    var showWorkFolder = Boolean(true); // shows(true)/hides(false) working folder in dialog
     
    var strWinTitle = String("Library opener");
    var strWorkFolder = String("Working folder:");
    var strSelectLib = String("Select library:");
    var strNoFiles = String("-- No libraries found --"); // shows if no libraries found
     
    ///////////////////////// SCRIPT /////////////////////////
     
    var myFiles = myWorkFolder.getFiles("*.indl");
    var myFilesNo = myFiles.length;
    var myLibFiles = Array();
     
    if(!myFilesNo){
         myLibFiles[0] = strNoFiles;
    }else{
         for(var i=0; i < myFilesNo; i++){
              myLibFiles.push(myFiles[i].displayName.substr(0,myFiles[i].displayName.lastIndexOf(".")));
         }
    }
     
    var myDialog = app.dialogs.add({name:strWinTitle, canCancel:true});
         with(myDialog){
              with(dialogColumns.add()){
                   if(showWorkFolder){
                        with(dialogRows.add()){
                             with(borderPanels.add()){
                                  with(dialogColumns.add()){
                                       staticTexts.add({staticLabel:strWorkFolder});
                                  }
                                  with(dialogColumns.add()){
                                       staticTexts.add({staticLabel:myWorkFolder.fsName});
                                  }
                             }
                        }
                   }
                   with(dialogRows.add()){
                        with(borderPanels.add()){
                             with(dialogColumns.add()){
                                  staticTexts.add({staticLabel:strSelectLib});
                             }
                             with(dialogColumns.add()){
                                  var myLib = dropdowns.add({stringList:myLibFiles, selectedIndex:0});
                             }
                        }
                   }
              }
         }
     
    if(myDialog.show() == true){
         if(myFilesNo){
              app.open(File(myFiles[myLib.selectedIndex]),false);
         }
    }
     
    myDialog.destroy();
    

     

    tomaxxi

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points