4 Replies Latest reply on Oct 1, 2016 1:37 PM by LLenoir

    How to stop error message on open file script

    LLenoir Level 1

      The below script I've been running for years. I use this to open specific folders so that I can choose the appropriate psd file for use. It works fine

      but sometimes after I execute the script and the open dialog box appears I decide not to choose one of the psd files and just close the dialog box.

      When I do this I get the below error message: Is there a way to modify this javascript so If I don't choose a psd file and close the dialog box I won't get the below message.

      PhotoshopError.png

      Below is my script:

      // UI strings to be localized

      var uiTitleSelectGridFile = "Select a Texture file";

       

      var folder = new Folder(app.path.parent + "/Photoshop Plugins Presets N Stuff/Textures")

      var openFile = folder.openDlg(uiTitleSelectGridFile, "PSD:*.psd");

      open (openFile);

        • 1. Re: How to stop error message on open file script
          try67 MVP & Adobe Community Professional

          [Question moved to the PS Scripting forum]

          • 2. Re: How to stop error message on open file script
            JJMack Most Valuable Participant

            If you did not select a file to open the variable openFile would not be set by the open file dialog you canceled with a close. So the open the script tried had no file set it was missing because you did not select a file to open.   The script does not have code to handle the case where no file was selected.  The scripted design requires you to select a file to open. Selection a file is required it not optional.

             

            You can add code to  handle no file was selected.  However, the script is coded to process the file selected. You would need to add code to do something else if none is selected.

            • 3. Re: How to stop error message on open file script
              Mikaeru69 Level 3

              From http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/scripting/pdfs/javascript_tools_gui de.pdf:

               

              openDlg()

               

              fileObj.OpenDlg ([prompt][,filter][,multiSelect])

              prompt Optional. A string containing the prompt text, if the dialog allows a prompt.

              filter Optional. A filter that limits the types of files displayed in the dialog.

              In Windows, a filter expression, such as "JavaScript:*.jsx;All files:*.*"

              In Mac OS, a filter function that takes a File instance and returns true if the file

              should be included in the display, false if it should not.

              multiSelect Optional. Boolean. When true, the user can select multiple files and the return value

              is an array. Default is false.

              Opens the built-in platform-specific file-browsing dialog, in which the user can select an existing file

              or files, and creates new File objects to represent the selected files. Differs from the class method

              openDialog() in that it presets the current folder to this File object’s parent folder and the current

              file to this object’s associated file.

              If the user clicks OK, returns a File or Folder object for the selected file or folder, or an array of

              objects. If the user cancels, returns null.

               

              The result of the call to openDlg must be not null before attempting to use it a File object:

               

              // UI strings to be localized
              var uiTitleSelectGridFile = "Select a Texture file";
              
              var folder = new Folder(app.path.parent + "/Photoshop Plugins Presets N Stuff/Textures")
              var openFile = folder.openDlg(uiTitleSelectGridFile, "PSD:*.psd");
              if (openFile)
              {
                   open (openFile);
              }
              

               

              HTH...

              • 4. Re: How to stop error message on open file script
                LLenoir Level 1

                Thanks that is exactly what I needed.