Skip to main content
Inspiring
August 26, 2014
Answered

Is it possible to script a Pause, allowing brushing etc

  • August 26, 2014
  • 4 replies
  • 8549 views

I use a workflow script and actions to retouch large numbers of files and it would be fabulous if I could do some layer mask brushing on each image "mid batch". Is it possible to create a Pause Script (60-120 seconds would be ideal) that can be called from an action or inserted into my pressing script?

Can anyone tell me a) if this possible b) which Javascript commands I should try ?

This topic has been closed for replies.
Correct answer r-bin

Works well on CS6.

Worse on CC2018 due to the use of refresh()

You can draw, adjust adjustments layers and even invoke other scripts.

var cs6 = (parseInt(app.version)==13)

var time = 60;

var old_time;

var msg = new Window("palette", "Draw or do something while script is waiting");

msg.preferredSize.width = 200;

msg.txt = msg.add("statictext", undefined, "");

msg.txt.preferredSize.width = 220;

msg.txt.justify = "center";

msg.btn = msg.add("button", undefined, "Continue");

msg.btn.onClick = function() { msg.hide(); }

msg.show();

msg.frameLocation = [50, 100];

$.hiresTimer;

set_performance("stepByStep");

app.displayDialogs = DialogModes.ERROR;

try {

    while (msg.visible && time > 0)

        {

        if (old_time != time.toFixed(0))

            {

            msg.txt.text = "You have: " + time.toFixed(0) + " sec";

            old_time = time.toFixed(0);

            }

        if (cs6) app.bringToFront();

        else     app.refresh(); 

        time -= ($.hiresTimer/1000000);

        }

    }

catch (e) { }           

set_performance("accelerated");

msg.close();

alert("Script End")

function set_performance(mode)

    {

    try {

        var r1 = new ActionReference();

        r1.putProperty( charIDToTypeID( "Prpr" ), charIDToTypeID( "PbkO" ) );

        r1.putEnumerated( charIDToTypeID( "capp" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );

        var d1 = new ActionDescriptor();

        d1.putReference( charIDToTypeID( "null" ), r1 );

        var d2 = new ActionDescriptor();

        d2.putEnumerated( stringIDToTypeID( "performance" ), stringIDToTypeID( "performance" ), stringIDToTypeID( mode ) );

        d1.putObject( charIDToTypeID( "T   " ), charIDToTypeID( "PbkO" ), d2 );

        executeAction( charIDToTypeID( "setd" ), d1, DialogModes.NO );

        }

    catch (e) { throw(e); }

    }

4 replies

r-binCorrect answer
Legend
February 21, 2018

Works well on CS6.

Worse on CC2018 due to the use of refresh()

You can draw, adjust adjustments layers and even invoke other scripts.

var cs6 = (parseInt(app.version)==13)

var time = 60;

var old_time;

var msg = new Window("palette", "Draw or do something while script is waiting");

msg.preferredSize.width = 200;

msg.txt = msg.add("statictext", undefined, "");

msg.txt.preferredSize.width = 220;

msg.txt.justify = "center";

msg.btn = msg.add("button", undefined, "Continue");

msg.btn.onClick = function() { msg.hide(); }

msg.show();

msg.frameLocation = [50, 100];

$.hiresTimer;

set_performance("stepByStep");

app.displayDialogs = DialogModes.ERROR;

try {

    while (msg.visible && time > 0)

        {

        if (old_time != time.toFixed(0))

            {

            msg.txt.text = "You have: " + time.toFixed(0) + " sec";

            old_time = time.toFixed(0);

            }

        if (cs6) app.bringToFront();

        else     app.refresh(); 

        time -= ($.hiresTimer/1000000);

        }

    }

catch (e) { }           

set_performance("accelerated");

msg.close();

alert("Script End")

function set_performance(mode)

    {

    try {

        var r1 = new ActionReference();

        r1.putProperty( charIDToTypeID( "Prpr" ), charIDToTypeID( "PbkO" ) );

        r1.putEnumerated( charIDToTypeID( "capp" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );

        var d1 = new ActionDescriptor();

        d1.putReference( charIDToTypeID( "null" ), r1 );

        var d2 = new ActionDescriptor();

        d2.putEnumerated( stringIDToTypeID( "performance" ), stringIDToTypeID( "performance" ), stringIDToTypeID( mode ) );

        d1.putObject( charIDToTypeID( "T   " ), charIDToTypeID( "PbkO" ), d2 );

        executeAction( charIDToTypeID( "setd" ), d1, DialogModes.NO );

        }

    catch (e) { throw(e); }

    }

Gabarito
Known Participant
February 21, 2018

Very interesting!!!

It's what I was looking for.

But where do I put my code?

Inside that try statement?

try { 

    while (msg.visible && time > 0) 

        { 

        if (old_time != time.toFixed(0)) 

            { 

            msg.txt.text = "You have: " + time.toFixed(0) + " sec"; 

            old_time = time.toFixed(0); 

            } 

  Here???

        if (cs6) app.bringToFront(); 

        else     app.refresh();   

  Here??? 

        time -= ($.hiresTimer/1000000); 

        } 

    } 

catch (e) { }             

So, where?

Legend
February 21, 2018

Place the first part of your code before all this script. Place the second part instead of the alert ("Script End") command.

It's better to make my entire script as a function and call it in the necessary places in your scripts.

Known Participant
August 28, 2014

OrchidPhoto,

You can try running the first half of the script normally, then show a ScriptUI palette where you want to break. The palette should contain a 'Continue' button. Add the rest of the functionality of the script to the callback of this Continue button.

JJMack
Community Expert
Community Expert
February 20, 2018

Photoshop ScriptUI does not actually support Palette Windows in a Photoshop Script run in from Photoshop. The Script though suspended and waiting on the palette being used.  Photoshop UI is not given back control.  So the user can do nothing in Photoshop but use the Palette window.  I have been able to write a Photoshop Script that opens palette window from a Photoshop Extention and use Photoshop with the Palette window open.

JJMack
JJMack
Community Expert
Community Expert
August 27, 2014

OrchidPhoto wrote:

I use a workflow script and actions to retouch large numbers of files and it would be fabulous if I could do some layer mask brushing on each image "mid batch". Is it possible to create a Pause Script (60-120 seconds would be ideal) that can be called from an action or inserted into my pressing script?

"that can be called from an action"   I do not understand if your using an action to begin with you can pause an action with a stop message like "Piant on the layer mask to make it better. When done click on "PLAY" in the Actions Palette  to continue the action.


However you also write batch.   Having interaction in a batch process sort of negate it being a batch process.

JJMack
AviMathur
Adobe Employee
Adobe Employee
September 11, 2014

hey JJMack can you provide an example..

Gabarito
Known Participant
February 20, 2018

I posted a link to wrong pdf see if the one is OK JavaScript Tools Guide CC.pdf

 


Far better PDF.

I have too many lessons to study...

Thanks.

But how do you debug your scripts?

How do you run step-by-step your codes?

pixxxelschubser
Community Expert
Community Expert
August 26, 2014

Hi OrchidPhoto,

yes, you can say: "script wait any time" e.g. like this:

alert("wait a second");

$.sleep( 999 ); /*Milliseconds*/

alert ("done");

But in this time IMHO the script is always activ and you cannot work in PS meantime, sorry.