4 Replies Latest reply: Oct 19, 2014 2:51 AM by c.pfaffenbichler RSS

    How to attach a UI dialog to a script?

    ojodegato Community Member

      I use a custom script to batch process files into photoshop layers.

      Every time I run the script I have to manually edit the folder path in the script to save the new images in a new folder.

       

      Can a UI dialog be implemented into a script used for batch file processing?

       

      The UI dialog:

      Enter folder path

      Remember the last folder path used

       

      When the scripts runs the UI dialog displays. After the user enters the folder path the the scripts batch processes a folder of images.

        • 1. Re: How to attach a UI dialog to a script?
          c.pfaffenbichler Community Member

          Instead of entering the path manually would a folder selection dialog not be more convenient?

          var theFolder = Folder.selectDialog ("select folder");

          if (theFolder) {

          var theFiles = theFolder.getFiles(/\.(jpg|tif|eps|psd)$/i)

          };

          • 2. Re: How to attach a UI dialog to a script?
            Matias Kiviniemi Community Member

            And you can save the data by putting it to an action descriptor and saving to custom options. I have assumption about JSON encoding, but many other ways of stuffing things to action descriptors are possible.

             

            savePreferences: function (metadata) {
              var metadata_json = serialize_to_json(metadata)
              var desc = new ActionDescriptor()
              desc.putData(0, metadata_json)
              app.putCustomOptions (APP_ID, desc, true)
            },
            loadPreferences: function () {
              try {
              var desc = app.getCustomOptions (APP_ID)
              if (desc) {
              var metadata_json = desc.getData(0)
              if (metadata_json) {
              eval("var result = (" + metadata_json + ")")
              if (result) {
              return result
              }
              }
              }
              } catch (e) {
              var foo = e.message
              } 
            },
            
            • 3. Re: How to attach a UI dialog to a script?
              ojodegato Community Member

              I try the Folder dialog but the Bridge script does not complete when using this option.

              I would like to save the new tiff file  in the same directory with the stack images.

              Is there a way to omit the save location path to save the tiff in the same directory as the Bridge stack images?

               

                      var stackFileName = app.activeDocument.name;

                      var saveFile = new File('~/desktop/pscc test/'+stackFileName+' ');

                      app.activeDocument.saveAs(saveFile, tifOpts, true); 

                      app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

              • 4. Re: How to attach a UI dialog to a script?
                c.pfaffenbichler Community Member

                There is a Bridge Scripting Forum, too, maybe you should post there.