12 Replies Latest reply on Mar 17, 2016 8:49 AM by 1CM69

    Alert user to choose folder

    1CM69 Level 1

      Hi all,

       

      very new to scripting and am a little stuck.

       

      I have produced a script that works but I wish to refine it some more to make it more user friendly.

       

      When the script starts it asks the user to choose a folder where their images are located but there are two issues with this.

       

      Firstly as the dialog defaults to the DESKTOP folder and the user accidentally presses OK, the script will proceed even if this is the incorrect location.

       

      Secondly there is no exit procedure if the uses instead presses CANCEL on the dialog.

       

      I am trying to implement a fail-safe so  the end user will have feedback i.e. when pressing OK a popup will ask the user if the folder 'x' is the correct location and give a YES/NO dialog - YES to proceed - NO goes back to folder chooser screen.

       

      Also I need to make the script exit cleanly if the user chooses the CANCEL button on the folder chooser screen.

       

      Here is a snippet of my code as it stands:

       

      // Ask user for DARK input folder
      alert("Please Choose The Folder Where Your DARK Frames are located.", "DARK FRAME FOLDER LOCATION");
      
      
      var DARKinputFolder = Folder.selectDialog("****Please Select The Folder Where Your DARK FRAMES Are Located****");
      
      
      // Ask user for LIGHTS input folder
      alert("Please Choose The Folder Where Your LIGHT Frames are located.", "LIGHT FRAME FOLDER LOCATION");
      
      
      var LIGHTSinputFolder = Folder.selectDialog("****Please Select The Folder Where Your LIGHT FRAMES Are Located****");
      
      
      // ***HANDLE THE DARK FRAMES***
      
      
      // get all files in the DARK input folder
      var FILE_TYPE = ".orf"; // The type of files that this script works on -- you can change
      var SEARCH_MASK = "*" + FILE_TYPE; // Image file filter to find only those files
      var DARKfileList = DARKinputFolder.getFiles(SEARCH_MASK);
      
      
      if (DARKfileList.length <= 0)
      {
      var FILE_TYPE = ".tif"; // The type of files that this script works on -- you can change
      var SEARCH_MASK = "*" + FILE_TYPE; // Image file filter to find only those files
      var DARKfileList = DARKinputFolder.getFiles(SEARCH_MASK);
      }
      
      
      if (DARKfileList.length <= 0)
      {
      var FILE_TYPE = ".tiff"; // The type of files that this script works on -- you can change
      var SEARCH_MASK = "*" + FILE_TYPE; // Image file filter to find only those files
      var DARKfileList = DARKinputFolder.getFiles(SEARCH_MASK);
      }
      
      
      if (DARKfileList.length <= 0)
      {
      var FILE_TYPE = ".jpg"; // The type of files that this script works on -- you can change
      var SEARCH_MASK = "*" + FILE_TYPE; // Image file filter to find only those files
      var DARKfileList = DARKinputFolder.getFiles(SEARCH_MASK);
      }
      
      
      if (DARKfileList.length <= 0)
      {
      var FILE_TYPE = ".jpeg"; // The type of files that this script works on -- you can change
      var SEARCH_MASK = "*" + FILE_TYPE; // Image file filter to find only those files
      var DARKfileList = DARKinputFolder.getFiles(SEARCH_MASK);
      }
      

       

      Any help would be appreciated

       

      Kind regards..,

        • 1. Re: Alert user to choose folder
          Chuck Uebele Adobe Community Professional & MVP

          You need error checking and you need to define a starting folder.

           

           

          var myFolder = new Folder('/c/theStartingFolder');//create a folder to have the dialog start on.
          var holdFolder = new Folder();//create a holding folder for canceling.
          
          dlg.getTheFilesBtn = dlg.add('button',undefined,'Select a folder');//part of ui to create button
          
          dlg.getTheFilesBtn.onClick = function(){
               holdFolder = new Folder(myFolder);//stores the current folder in case of cancel.
               holdFolder = Folder.selectDialog('select a folder to process',myFolder);//opens the folder browse UI using you main folder.
               If(holdFolder){myFolder = holdFolder};//if cancel is hit, this statement becomes false, and myFolder remains untouched.
               //if it's true, then the selected folder from the holdFolder is transferred to myfolder.
          }
          
          • 2. Re: Alert user to choose folder
            1CM69 Level 1

            Thanks for replying but I am still stuck.

             

            I tried placing the code you posted above the code I pasted in my first post but it does not seem to do anything. When I run the script in PS the first thing that shows is the first ALERT message as in my original code.

             

            Regards..,

            • 3. Re: Alert user to choose folder
              Chuck Uebele Adobe Community Professional & MVP

              You should create a custom UI rather than the alerts to do this.

              • 4. Re: Alert user to choose folder
                Chuck Uebele Adobe Community Professional & MVP
                var myFolder = new Folder('/c/theStartingFolder');//create a folder to have the dialog start on.  
                var holdFolder = new Folder();//create a holding folder for canceling.  
                var dlg = new Window('dialog','Select a folder')
                dlg.getTheFilesBtn = dlg.add('button',undefined,'Select a folder');//part of ui to create button  
                
                dlg.getTheFilesBtn.onClick = function(){  
                     holdFolder = new Folder(myFolder);//stores the current folder in case of cancel.  
                     holdFolder = Folder.selectDialog('select a folder to process',myFolder);//opens the folder browse UI using you main folder.  
                     If(holdFolder){myFolder = holdFolder};//if cancel is hit, this statement becomes false, and myFolder remains untouched.  
                    //if it's true, then the selected folder from the holdFolder is transferred to myfolder.  
                dlg.close()
                }
                dlg.show()
                
                
                • 5. Re: Alert user to choose folder
                  1CM69 Level 1

                  Hi,

                   

                  thanks again for replying.

                   

                  I think I am getting somewhere although ExtendScript ToolKit keeps throwing errors.

                   

                  1st a missing ';' in this line:

                   

                  If(holdFolder){myFolder = holdFolder};//if cancel is hit, this statement becomes false, and myFolder remains untouched.
                  

                   

                  seemed OK if I changed line to:

                   

                  If(holdFolder);{myFolder = holdFolder};//if cancel is hit, this statement becomes false, and myFolder remains untouched.
                  

                   

                  but now complains that the above line is not a function.

                   

                  Regards..,

                  • 6. Re: Alert user to choose folder
                    Chuck Uebele Adobe Community Professional & MVP

                    There was a typo in the above code. You're putting the ";" is not right. I put a cap i for if and that is wrong. The code should be:

                     

                    var myFolder = new Folder('/c/test');
                    var holdFolder = new Folder()
                    
                    var dlg = new Window('dialog','Select a Folder');
                        dlg.getTheFilesBtn = dlg.add('button',undefined,'Select a folder');
                            dlg.getTheFilesBtn.onClick = function(){
                                holdFolder = new Folder(myFolder);
                                holdFolder = Folder.selectDialog('select a folder to process',myFolder);
                                if(holdFolder){myFolder = holdFolder};
                                dlg.close();
                            }
                            dlg.show()
                    
                    • 7. Re: Alert user to choose folder
                      1CM69 Level 1

                      OK, thanks.

                      • 8. Re: Alert user to choose folder
                        1CM69 Level 1

                        Hi,

                         

                        just a quick question but the line:


                        var myFolder = new Folder('/c/test');


                        I would like to change to:


                        var myFolder = new Folder('C:\');


                        to display this variable in a text label but it throws an error because it is not escaped.


                        if I change the line to:


                        var myFolder = new Folder('/c/');


                        the error does not happen but when I then use the variable myFolder as the text for the static text label it displays as /c, which look nothing like the actual drive letter format i.e. C:\


                        How is it possible to display the proper format drive letter plus colon plus backslash inside the static text label using the myFolder variable?


                        Regards..,

                        • 9. Re: Alert user to choose folder
                          1CM69 Level 1

                          Don't worry, I have figured it out, I used:


                          label.text = 'C:' + String.fromCharCode (92);

                          • 10. Re: Alert user to choose folder
                            Chuck Uebele Adobe Community Professional & MVP

                            You can also do this:

                             

                            #target photoshop
                            var p = new Folder('/c/')
                            var d = new Window('dialog','test')
                            d.t = d.add('statictext',undefined,p.fsName)
                            d.show()
                            
                            

                             

                            Or this:

                             

                            #target photoshop
                            var p = new Folder('C:\\')
                            var d = new Window('dialog','test')
                            d.t = d.add('statictext',undefined,p.fsName)
                            d.show()
                            
                            • 11. Re: Alert user to choose folder
                              1CM69 Level 1

                              thanks