4 Replies Latest reply on Nov 5, 2017 11:24 AM by Zeeto

    Action to run script with dialog box shown only once.

    Zeeto Level 1

      Hello,

       

      I need to create an action, that runs the script. This script displays a dialog box, with various variables for user to select.

      When I choose Automate > Batch and select this action, the dialog box appears for every image.

       

      Is there any way to show the dialog box only once and apply the variables values set within this dialog box to the whole batch of images I want to process?

       

      Thank you!

        • 1. Re: Action to run script with dialog box shown only once.
          r-bin Level 4

          You can use get_run_counter() set_run_counter() or _get_run_counter() _set_run_counter() functions to determine the number of script starts since the start of the photoshop.

           

          ///////////////

          var options_name = "My Options";

           

          alert (get_run_counter())

          inc_run_counter();

           

          alert (_get_run_counter())

          _inc_run_counter();

           

           

          ////////////////////////////////////////////////////////////////////////////////////////// //

          function get_run_counter()

              {

              var d = null;

              try { d = app.getCustomOptions(options_name); } catch(e) { d = null; }

            

              if (!d) return 0;

           

              return d.getInteger(0);

              }

           

           

          ////////////////////////////////////////////////////////////////////////////////////////// //

          function inc_run_counter()

              {

              var cnt = get_run_counter();

           

              var d = new ActionDescriptor();

           

              d.putInteger( 0, cnt+1);

           

              app.putCustomOptions(options_name, d, true);

              }

           

          ////////////////////////////////////////////////////////////////////////////////////////// //

          function _get_run_counter()

              {

              var cnt = $.getenv(options_name);

              if (cnt == null || cnt == undefined) return 0;

           

              return Number(cnt);

              }

           

          ////////////////////////////////////////////////////////////////////////////////////////// //

          function _inc_run_counter()

              {

              var cnt = _get_run_counter();

           

              ++cnt;

           

              $.setenv(options_name, cnt.toFixed(0));

              }

          2 people found this helpful
          • 2. Re: Action to run script with dialog box shown only once.
            SuperMerlin Level 5

            Another option is to call the script with the SHIFT key pressed then you can use..

            if (ScriptUI.environment.keyboardState.shiftKey){

                // UI goes here

                }

            //rest of code

             

            Then the UI will only be called the first time.

            3 people found this helpful
            • 3. Re: Action to run script with dialog box shown only once.
              Zeeto Level 1

              Thank you very much for your suggestion, your solution is helpful but it would require restarting Photoshop after every batch.

              • 4. Re: Action to run script with dialog box shown only once.
                Zeeto Level 1

                Thank you for your reply.

                 

                Although it is very clever, I need to call the action via File > Automate > Batch.

                Otherwise, I think my script could just use a dialog box to select a folder with images I want to execute the script on.