Hide/open UI windows with JS

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Kukurykus, Tom, xbytor

tyr

Hide/open UI windows with JS

Post by tyr »

Hey everyone.

Can you please tell me if there is a way to know if certain panels are opened? And open/close them with script?

For example, I want a script that
a) opens Brush and Layer panels if both of them are closed
and
b) closes them if they're opened together OR only one of them is opened.

Thanks,
Sergey

pfaffenbichler

Hide/open UI windows with JS

Post by pfaffenbichler »

One can determine if a Photoshop Panel is visible.
Code: Select all// check for panels;
// based on code by michael l hale;
// 2013, use it at your own risk;
#target photoshop
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var applicationDesc = executeActionGet(ref);
var panelList = applicationDesc.getList(stringIDToTypeID('panelList'));
for (var m = 0; m < panelList.count; m++) {
   var thisPanelDesc = panelList.getObjectValue(m);
   if (thisPanelDesc.getString(stringIDToTypeID("name")) == "Layers") {
      alert ("the panel "+thisPanelDesc.getString(stringIDToTypeID("name"))+" being visible is\n"+
      thisPanelDesc.getBoolean(stringIDToTypeID("visible")))
      };
   if (thisPanelDesc.getString(stringIDToTypeID("name")) == "Brush") {
      alert ("the panel "+thisPanelDesc.getString(stringIDToTypeID("name"))+" being visible is\n"+
      thisPanelDesc.getBoolean(stringIDToTypeID("visible")))
      };
   };

tyr

Hide/open UI windows with JS

Post by tyr »

Thanks pfaffenbichler!
Are those booleans read only? I can't figure out a way to turn them true or false

pfaffenbichler

Hide/open UI windows with JS

Post by pfaffenbichler »

Are you familiar with Action Manager code at all yet (as opposed to Document Object Model code)?

tyr

Hide/open UI windows with JS

Post by tyr »

Unfortunately no, I'm not a coder at all and I understand only the simplest things.
I realiz that probably I need to use 'putReference' somehow somewhere, but I have no idea how and where, a word of help is much appreciated!

pfaffenbichler

Hide/open UI windows with JS

Post by pfaffenbichler »

One »word« will likely not suffice.

Anyway, I used xbytor’s »ActionFileToJavascript.jsx« to get the code for an Action that toggles the Layers Panel (created via »Insert Menu Item«).
Code: Select all// thanks to xbytor;
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated(charIDToTypeID('Mn  '), charIDToTypeID('MnIt'), charIDToTypeID('Tgly'));
desc1.putReference(stringIDToTypeID('null'), ref1);
executeAction(charIDToTypeID('slct'), desc1, DialogModes.NO);

Unfortunately this seems to affect all Panels that are docked together.

tyr

Hide/open UI windows with JS

Post by tyr »

Interesting: this hides and unhides Layers panel, Brush stays intact. I can't understand how this works, and since I make this script for myself I think it'll be easier to make actions that hide/show panels and fire them depending of code you posted above. Ugly, but easy to do. Thanks again, pfaffenbichler!

pfaffenbichler

Hide/open UI windows with JS

Post by pfaffenbichler »

That code was only for the Layers Panel, for the Brush Panel it would be
Code: Select all// thanks to xbytor;
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated(charIDToTypeID('Mn  '), charIDToTypeID('MnIt'), charIDToTypeID('TglB'));
desc1.putReference(stringIDToTypeID('null'), ref1);
executeAction(charIDToTypeID('slct'), desc1, DialogModes.NO);

tyr

Hide/open UI windows with JS

Post by tyr »

Ah, fair enough, the only difference is that Tgly / TglB thing. MANY THANKS! Now everything works without actions

And thanks for pointing on xbytor's ActionFileToJavascript.jsx , amazing thing!

pfaffenbichler

Hide/open UI windows with JS

Post by pfaffenbichler »

Maybe it’s a little consolation: I can not claim that to fully comprehend Action Manager code, either.
But on the basis of the work of and code provided by xbytor, Mike Hale, Paul Riggott, … one can utilize it even without fully understanding it, I guess.