Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


PS SDK script crash due to UI lag

Participant ,
Nov 20, 2021 Nov 20, 2021

Copy link to clipboard

Copied

Hey

I'm on 2022.x I think latest.

Today I've cleaned up a rather large script. 

I've removed about 500 warrning/errors. Mostly just adding var xx and so on.

 

Once I wrapped it up I've run a test and I hit intereting error... I have a copy layer function (that I will update/rewrite now) but regardless the issue & action that I perfrom is as follow

 

for (var inx = layerCount - 1; inx >= 0; --inx) { 
     app.activeDocument = newDoc; // this is new file with many layers ion it
     currentDocumentLayers[inx].duplicate(mainDocument) // copy the file to specific document
     app.activeDocument = mainDocument; // activate the document
     layerList.push(mainDocument.activeLayer); // record newly added layer 
}

 

Now here is the "cool" thing. When running on old source, everything worked. But on new source, when I do app.activeDocument = newDoc  or app.activeDocument ==mainDocument... I get a crash(not exactly there, but it crashes on next action. But that action does not finish in time for PS). As when I watch PS, he tries to duplicate layer before even changing document. When I break point it, and do it by hand 1 by 1 calls (F10) there is no crash. But when he does auto, it crashes.

As far as I can tell, I need to call somehow on PS to update UI/events. 

 

So the question is... what command can I use to push/update photoshop to correct "state" after callinng app.activeDoc =xx?

 

TIA

TOPICS
Actions and scripting, Cross-app workflows, macOS, SDK, Windows

Views

129

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 20, 2021 Nov 20, 2021

Copy link to clipboard

Copied

quote

As far as I can tell, I need to call somehow on PS to update UI/events. 


By @Dariusz1989

 

Try to set Actions->Playback options->Step by step

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 21, 2021 Nov 21, 2021

Copy link to clipboard

Copied

That apperars to work! 

But now I have 2 more questions 😄 

Do you happen to know commands to

1. get current step by step setting 

2. set step by step settings?

If I am to use this option, I have to make sure I can enable/disable it on customer system & restore to previous state if different.

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 21, 2021 Nov 21, 2021

Copy link to clipboard

Copied

You can obtain that from: Saving JS settings in Actions Tutorial

 

I hope you know how to do that, same as we had, with not working snippet you provided 😉

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 21, 2021 Nov 21, 2021

Copy link to clipboard

Copied

Thank you! Looks promising, I'll dig in ! 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 21, 2021 Nov 21, 2021

Copy link to clipboard

Copied

Did you try refresh() method to solve the problem? / btw. next time please add only 'Actions and scripting' label to coding thread, unless there's need for assigning more specific ones, useful when browsing 😉

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 21, 2021 Nov 21, 2021

Copy link to clipboard

Copied

I'd love to change it update, but thats up to mods to give us that power... 

I'll try refresh() thank you!

I spend entire morning today trying to undertand how can I do executeActionGet() to get state of that settings but I failed so far :- (((

 

I've got this snippet to set it to stepByStep

	var idsetd = charIDToTypeID("setd");
	var desc232 = 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);
	desc232.putReference(idnull, ref1);
	var idT = charIDToTypeID("T   ");
	var desc233 = new ActionDescriptor();
	var idperformance = stringIDToTypeID("performance");
	var idperformance = stringIDToTypeID("performance");
	var idaccelerated = stringIDToTypeID("stepByStep");
	desc233.putEnumerated(idperformance, idperformance, idaccelerated);
	var idPbkO = charIDToTypeID("PbkO");
	desc232.putObject(idT, idPbkO, desc233);
	executeAction(idsetd, desc232, DialogModes.NO);

But how to store original value/restore after. Its a mystery. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 21, 2021 Nov 21, 2021

Copy link to clipboard

Copied

refresh() appaear to work with accelerated mode which overall speed up production as I don't have to wait for gui udpates! This is great, I'm now forcing updates where I need them in anticipation of an issue. Thanks!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 21, 2021 Nov 21, 2021

Copy link to clipboard

Copied

refresh() is not so good, as it takes one second to take effect. BridgeTalk method is better 😉

 

Anyway, if you're happy with any of our answers, mark appropriate post as correct solution.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 21, 2021 Nov 21, 2021

Copy link to clipboard

Copied

I don't know if it's possible to read Performance of Playback Options, so executeActionGet may not work here, how ever for you it's not important. I mean before you need StepByStep speed, set the script to it, and after doing the thing you changed the oprion for (so still during same script) change it to accelerated.

 

A workaround would be to run some non-time consuming action step by script. Depending how much time it took, you can know what performance option most possibly is set 😉

 

Ps. probably after posting 100 posts you'll be allowed to edit own comments.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 21, 2021 Nov 21, 2021

Copy link to clipboard

Copied

quote

	var idaccelerated = stringIDToTypeID("stepByStep");
	

But how to store original value/restore after. Its a mystery. 


By @Dariusz1989

 

 

stringIDToTypeID("stepByStep") -> stringIDToTypeID("accelerated")

 

p.s. You won't be able to read it, at least in cs6-cc 2020 (possibly a bug). 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 21, 2021 Nov 21, 2021

Copy link to clipboard

Copied

If you'd like to provide a code that in your opinion should read Performance of Playback Options I'll report a bug in Actions and scripting BUGS (unless you want to do it yourself). Probably similar one to do it is that for reading Add "copy" to Copied Layers and Groups of Layers Panel Options.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 21, 2021 Nov 21, 2021

Copy link to clipboard

Copied

quote

If you'd like to provide a code ....


By @Kukurykus

 

Well, this would have to work, if we take as a basis how this property was set

 

var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("playbackOptions"));
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var ret = executeActionGet(r);

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 21, 2021 Nov 21, 2021

Copy link to clipboard

Copied

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 21, 2021 Nov 21, 2021

Copy link to clipboard

Copied

Hey

Oh dear o.o This is interesting...

 

soo why do you put 

stringIDToTypeID("application")

And not "actions"/"actionSet"/"the "playbackThini" thini ?

One thing I'm struggling that I keep... "thinking" that there is some kind of structure in PS like

Application/ActionManager/undoManager/layerManager/etcManager.

And I have to find the correct manager when building ActionReference... but I keep failing to find the manager names or know where to look for stuff.

I've went over scripting guide/other pdfs I could find and its a bit... hard :- ( 

Should I target "application" for anything in Photoshop? Say... Edit>preferences> (anything here?) 

How is this stuff dividend internally if I want to reach each management system & read its data?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 21, 2021 Nov 21, 2021

Copy link to clipboard

Copied

That's logical to replace 'application' by something like 'action', but here the problem is that option is not available yet. To start understanding the subject read: Action Manager Scripting

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 21, 2021 Nov 21, 2021

Copy link to clipboard

Copied

Thats the exact post I was following today & trying to wrap my head around.

I tried reading script listener code, which did not mention any "act/action/actSet/etc" and then I went on wild gus chase on web that mostly ended up in zip. The posts above helped with exmaples/etc but still nothing near what I needed. 

Just feels very "random-brute forced" learning with very "smarty" system for building commands but no idea what command for what I need to build O.O 

I found this that helps a lot > 

https://github.com/jardicc/ActionManagerHumanizer

But even with that, I was like... "so how do I find action manager..." 

Maybe I should write a Js function that generates random words & run it via that "humanizer" and see wich randomly generated text phrases actually work & give some output o.o

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 21, 2021 Nov 21, 2021

Copy link to clipboard

Copied

LATEST

You're right about Brute Force. That's the method you must use to find all commands 😉

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 21, 2021 Nov 21, 2021

Copy link to clipboard

Copied

The code for the action to set playbackOptions parameters is obtained using the ScriptListener plugin.

Why the code looks like this you need to ask the photoshop developers. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines