Skip to main content
olivu1568674
Known Participant
October 2, 2018
Answered

Is there any way to prevent UI updating while JSX script is running in Photoshop?

  • October 2, 2018
  • 5 replies
  • 2698 views

Seems when we updating some contents of number of layers. It seems, photoshop consume lot of performance for updating preview in canvas.
Is there any way to stop updating while running the script?
Can we show updated preview result at the end of the script execution?

This topic has been closed for replies.
Correct answer Chuck Uebele

This is an old thread, but came up with another question. To speed up my scripts to avoid redraws, I use code to turn on and off action steps:

 

 

//function to set action playback to step by step so the screen refreshes when a dialog box comes up
function setActionToStep(){
	var idsetd = charIDToTypeID( "setd" );
		var desc1 = new ActionDescriptor();
		var idnull = charIDToTypeID( "null" );
			var ref1 = new ActionReference();
			var idPrpr = charIDToTypeID( "Prpr" );
			var idPbkO = charIDToTypeID( "PbkO" );
			ref1.putProperty( idPrpr, idPbkO );
			var idcapp = charIDToTypeID( "capp" );
			var idOrdn = charIDToTypeID( "Ordn" );
			var idTrgt = charIDToTypeID( "Trgt" );
			ref1.putEnumerated( idcapp, idOrdn, idTrgt );
		desc1.putReference( idnull, ref1 );
		var idT = charIDToTypeID( "T   " );
			var desc2 = new ActionDescriptor();
			var idperformance = stringIDToTypeID( "performance" );
			var idperformance = stringIDToTypeID( "performance" );
			var idstepByStep = stringIDToTypeID( "stepByStep" );
			desc2.putEnumerated( idperformance, idperformance, idstepByStep );
		var idPbkO = charIDToTypeID( "PbkO" );
		desc1.putObject( idT, idPbkO, desc2 );
	executeAction( idsetd, desc1, DialogModes.NO );
}//end function 

// function to return action to accelerated mode - no refresh of screen for each step.=======================================================
function setActionToAcc(){
	var idsetd = charIDToTypeID( "setd" );
		var desc3 = new ActionDescriptor();
		var idnull = charIDToTypeID( "null" );
			var ref2 = new ActionReference();
			var idPrpr = charIDToTypeID( "Prpr" );
			var idPbkO = charIDToTypeID( "PbkO" );
			ref2.putProperty( idPrpr, idPbkO );
			var idcapp = charIDToTypeID( "capp" );
			var idOrdn = charIDToTypeID( "Ordn" );
			var idTrgt = charIDToTypeID( "Trgt" );
			ref2.putEnumerated( idcapp, idOrdn, idTrgt );
		desc3.putReference( idnull, ref2 );
		var idT = charIDToTypeID( "T   " );
			var desc4 = new ActionDescriptor();
			var idperformance = stringIDToTypeID( "performance" );
			var idperformance = stringIDToTypeID( "performance" );
			var idaccelerated = stringIDToTypeID( "accelerated" );
			desc4.putEnumerated( idperformance, idperformance, idaccelerated );
		var idPbkO = charIDToTypeID( "PbkO" );
		desc3.putObject( idT, idPbkO, desc4 );
	executeAction( idsetd, desc3, DialogModes.NO );
}//end function

 

5 replies

Chuck Uebele
Community Expert
Chuck UebeleCommunity ExpertCorrect answer
Community Expert
September 9, 2022

This is an old thread, but came up with another question. To speed up my scripts to avoid redraws, I use code to turn on and off action steps:

 

 

//function to set action playback to step by step so the screen refreshes when a dialog box comes up
function setActionToStep(){
	var idsetd = charIDToTypeID( "setd" );
		var desc1 = new ActionDescriptor();
		var idnull = charIDToTypeID( "null" );
			var ref1 = new ActionReference();
			var idPrpr = charIDToTypeID( "Prpr" );
			var idPbkO = charIDToTypeID( "PbkO" );
			ref1.putProperty( idPrpr, idPbkO );
			var idcapp = charIDToTypeID( "capp" );
			var idOrdn = charIDToTypeID( "Ordn" );
			var idTrgt = charIDToTypeID( "Trgt" );
			ref1.putEnumerated( idcapp, idOrdn, idTrgt );
		desc1.putReference( idnull, ref1 );
		var idT = charIDToTypeID( "T   " );
			var desc2 = new ActionDescriptor();
			var idperformance = stringIDToTypeID( "performance" );
			var idperformance = stringIDToTypeID( "performance" );
			var idstepByStep = stringIDToTypeID( "stepByStep" );
			desc2.putEnumerated( idperformance, idperformance, idstepByStep );
		var idPbkO = charIDToTypeID( "PbkO" );
		desc1.putObject( idT, idPbkO, desc2 );
	executeAction( idsetd, desc1, DialogModes.NO );
}//end function 

// function to return action to accelerated mode - no refresh of screen for each step.=======================================================
function setActionToAcc(){
	var idsetd = charIDToTypeID( "setd" );
		var desc3 = new ActionDescriptor();
		var idnull = charIDToTypeID( "null" );
			var ref2 = new ActionReference();
			var idPrpr = charIDToTypeID( "Prpr" );
			var idPbkO = charIDToTypeID( "PbkO" );
			ref2.putProperty( idPrpr, idPbkO );
			var idcapp = charIDToTypeID( "capp" );
			var idOrdn = charIDToTypeID( "Ordn" );
			var idTrgt = charIDToTypeID( "Trgt" );
			ref2.putEnumerated( idcapp, idOrdn, idTrgt );
		desc3.putReference( idnull, ref2 );
		var idT = charIDToTypeID( "T   " );
			var desc4 = new ActionDescriptor();
			var idperformance = stringIDToTypeID( "performance" );
			var idperformance = stringIDToTypeID( "performance" );
			var idaccelerated = stringIDToTypeID( "accelerated" );
			desc4.putEnumerated( idperformance, idperformance, idaccelerated );
		var idPbkO = charIDToTypeID( "PbkO" );
		desc3.putObject( idT, idPbkO, desc4 );
	executeAction( idsetd, desc3, DialogModes.NO );
}//end function

 

microbians
Known Participant
March 18, 2023

Thanks a lot this is working for update windows and not all the UI and composition of the PSD. Is very fast.

Participant
September 9, 2022

Can anyone tell me how can I controll photoshop after run my script... For example I want a pannel window which have 2 button and on those button there is a function like to save image or blur or any filter I want individual...so when I run script it is not allowing photoshop to open document or other operation on photoshop... So is there any way to working in photoshop during script running

 

 

 

Stephen Marsh
Community Expert
Community Expert
September 9, 2022

As mentioned in your other topic, this would require and extension panel, not a script.

Participant
September 17, 2022

so is there any way to creat a panel for photoshop cs5 version. i tried uxp developer tool but it dosen't support blow cc2020 version

Legend
October 3, 2018

With the panels turned off, the speed can be increased if the document is placed in a floating window with a minimum zoom and window size.

You can check.

$.hiresTimer;

for (var i = 0; i < 500; i++)

    app.activeDocument.artLayers.add();

var d = new ActionDescriptor();

var r = new ActionReference();

r.putIndex(stringIDToTypeID("snapshotClass"), 1);

d.putReference(stringIDToTypeID("null"), r);

executeAction(stringIDToTypeID("select"), d, DialogModes.NO);

alert("Done in " + ($.hiresTimer/1000000).toFixed(2) + " seconds", "Timer");

JJMack
Community Expert
Community Expert
October 3, 2018

That would seem correct to me.  I have tried to find a way to Automate minimizing  a floating window so there would be nothing that Photoshop would need to refresh.  However theres is no interface except Photoshop UI window frame controls to do that.  There is no shortcut or menu item to minimize a window.

JJMack
Stephen Marsh
Community Expert
Community Expert
October 3, 2018

In addition to turning off panels, perhaps zooming in to 12800% then returning to 100% or fit on screen?

Kukurykus
Legend
October 3, 2018

Why that percent of zooming?

Stephen Marsh
Community Expert
Community Expert
October 3, 2018

To limit what is redrawn, if that is a possible slowdown factor (which is why my response was worded as a question, I’m just guessing and don’t know if it is a factor or not).

JJMack
Community Expert
Community Expert
October 2, 2018

I turn most of it off by toggling the Palette at the beginning and end of the script.  The image update seems to be a low priority when it come to Photoshop Updating all the visible palettes slows down the script 

app.togglePalettes();

JJMack