Skip to main content
Known Participant
October 29, 2017
Question

Action to run script with dialog box shown only once.

  • October 29, 2017
  • 2 replies
  • 1253 views

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!

This topic has been closed for replies.

2 replies

SuperMerlin
Inspiring
October 29, 2017

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.

ZeetoAuthor
Known Participant
November 5, 2017

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.

Legend
October 29, 2017

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));

    }

ZeetoAuthor
Known Participant
November 5, 2017

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