Code or clever workaround for fail safe toggling of palettes into view?

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

skrippy
Posts: 14
Joined: Sun Nov 27, 2016 5:34 am
Location: EU

Code or clever workaround for fail safe toggling of palettes into view?

Post by skrippy »

There are several "events" or actions where I like to have a specific palette pop/toggle into view 8-)

When you are careful you can often prevent these toggles from making your palette disappear instead (by planning to not have it active when it likely gets toggled), but I have not yet found a fail safe method (in many years using actions) ...

Am I missing something, or are they making our life difficult...? :mrgreen:
I'd like to have a "show" command besides "toggle"...

I'm now implementing a few with an event script, so more options may be available...?

For example, can I check if that palette is already active/foremost to decide if I still have to toggle it?
(I'm interested to know this for Paths and Layer Comps)

I can also have a "Close Document" event script that makes things safer by making sure my default palettes are left visible again, but here is one example of a gotcha...:

When opening a document with more than one layer, I like the Layer Comps to pop into view (cause I often forget that I made some).

Now, when executing the following code I can have my palette disappear if I "quickly" open two consecutive multiple layer documents...
I can always make silly workarounds to diminish risk some more, but it has never been completely fail safe so far...

P.S. Finally tried xtools as well. Some handy stuff :o TYVM xbytor.
Some of the descriptions in ActionToJavascript.jsx made me hope the code was gonna be short and native, but it is quite verbose... (but a lifesaver of course :) ).
#target photoshop

if ( doc.layers.length !== 1 ) {

// toggle Layer Comps palette (code produced by xbytor's ActionToJavascript.jsx in xtools)

cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };

function toggleLayerComps() {
// Select
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated(cTID('Mn '), cTID('MnIt'), sTID("toggleCompsPalette"));
desc1.putReference(cTID('null'), ref1);
executeAction(cTID('slct'), desc1, dialogMode);
};
step1(); // Select
};

toggleLayerComps.main = function () {
toggleLayerComps();
};
toggleLayerComps.main();

}

skrippy
Posts: 14
Joined: Sun Nov 27, 2016 5:34 am
Location: EU

Re: Code or clever workaround for fail safe toggling of palettes into view?

Post by skrippy »

I think I'm gonna find some goodies in this one...

Hide/open UI windows with JS (2013)
www.ps-scripts.com/viewtopic.php?f=66&t=8219

skrippy
Posts: 14
Joined: Sun Nov 27, 2016 5:34 am
Location: EU

Re: Code or clever workaround for fail safe toggling of palettes into view?

Post by skrippy »

^ This kind of thing is indeed generally working :)

Except, the obvious and seemingly existing 'closeLayerCompsPanel' is not working for me (Adobe bug?).

So I have to blast the whole LayerCompsPanelGroup which can give a small jump on the screen...

Code: Select all

#target photoshop

if ( doc.layers.length !== 1 ) {

// show Layer Comps palette

app.runMenuItem (app.stringIDToTypeID ("closeLayerCompsPanelGroup")); // 'closeLayerCompsPanel' NOT working?
app.runMenuItem (app.stringIDToTypeID ("toggleCompsPalette"));

}

JavierAroche
Posts: 29
Joined: Sat Jul 30, 2016 3:52 am
Location: San Francisco

Re: Code or clever workaround for fail safe toggling of palettes into view?

Post by JavierAroche »

Hmm that's weird. Both of these commands close the layer comps panel for me. I'm using Photoshop CC 2015.0 on MacOS

Code: Select all


app.runMenuItem(stringIDToTypeID("closeLayerCompsPanel"));

Code: Select all


var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID('Mn '), charIDToTypeID('MnIt'), stringIDToTypeID('closeLayerCompsPanel'));
desc.putReference(charIDToTypeID('null'), ref);
executeAction(charIDToTypeID('slct'), desc, DialogModes.NO);

skrippy
Posts: 14
Joined: Sun Nov 27, 2016 5:34 am
Location: EU

Re: Code or clever workaround for fail safe toggling of palettes into view?

Post by skrippy »

I took out all my repeated "app." prefixes and now it works.

Thanks for another great fix, Javier :)