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: Tom, Kukurykus

Mikaeru

Hide/open UI windows with JS

Post by Mikaeru »

• It should be noted that, from Photoshop CS4, one can use the app.runMenuItem () method instead of Action Manager code. For instance:

Code: Select allapp.runMenuItem (app.stringIDToTypeID ("toggleBrushesPalette"));
is equivalent to:

Code: Select allfunction selectMenuItem (menuID)
{
   var desc = new ActionDescriptor ();
   var ref = new ActionReference ();
   ref.putEnumerated (app.stringIDToTypeID ("menuItemClass"), app.stringIDToTypeID ("menuItemType"), menuID);
   desc.putReference (app.stringIDToTypeID ("target"), ref);
   app.executeAction (app.stringIDToTypeID ("select"), desc, DialogModes.NO);
}
selectMenuItem (app.stringIDToTypeID ("toggleBrushesPalette"));

• Also, the possibility of determining if a Photoshop Panel is visible appears to be only available in recent versions (possibly CS5 or CS6?). However, it is possible to *close* (but not *open*) a panel (or a panel group) by using the appropriate menu item.

Consequently, from CS4, and regardless of the panel/palette visibility status:

Code: Select allapp.runMenuItem (app.stringIDToTypeID ("closeBrushesPanel"));
will always hide the Brush Panel for instance, and:

Code: Select allapp.runMenuItem (app.stringIDToTypeID ("closeBrushesPanel"));
app.runMenuItem (app.stringIDToTypeID ("toggleBrushesPalette"));

will always (re)display it...
tyr

Hide/open UI windows with JS

Post by tyr »

Wow, Mikaeru, thanks for runMenuItem! Does this work with custom panels?

If anyone interested here's the script I ended up with (with my friend's huge help on optimizing it, plus we had to modify it for custom panels two because their Action Manager code was different)

Code: Select allvar ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var applicationDesc = executeActionGet(ref);
var panelList = applicationDesc.getList(stringIDToTypeID('panelList'));

var affectedPanels = {   "Layers": [charIDToTypeID('Mn  '), charIDToTypeID('MnIt'), charIDToTypeID("Tgly")],
                                   "Brush": [charIDToTypeID('Mn  '), charIDToTypeID('MnIt'), charIDToTypeID("TglB")],
                                   "Tools": [charIDToTypeID('Mn  '), charIDToTypeID('MnIt'), charIDToTypeID("TglT")],
                                   "ColorAff": [charIDToTypeID('Mn  '), "ColorAff"],
                                   "sup2": [charIDToTypeID('Mn  '), "sup2"]
                                   };
var closing = false;

for (var m = 0; m < panelList.count; m++) {
    var thisPanelDesc = panelList.getObjectValue(m);
    var panelName = thisPanelDesc.getString(stringIDToTypeID("name"));
    if (affectedPanels[panelName]) {
        var isVisible = thisPanelDesc.getBoolean(stringIDToTypeID("visible"));
        if (isVisible) {
            closing = true;
            break;
        }
    };
};

for (var m = 0; m < panelList.count; m++) {
    var thisPanelDesc = panelList.getObjectValue(m);
    var panelName = thisPanelDesc.getString(stringIDToTypeID("name"));
   
    if (affectedPanels[panelName]) {
        var isVisible = thisPanelDesc.getBoolean(stringIDToTypeID("visible"));
        if ((closing && isVisible) || (!closing && !isVisible)) {
            changeVisibility(affectedPanels[panelName]);
        }
    };
};

function changeVisibility(panelParams) {
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
     if (panelParams.length == 3) {
    ref1.putEnumerated.apply(ref1,panelParams);
    } else {
        ref1.putName.apply(ref1,panelParams);
        }
    desc1.putReference(stringIDToTypeID('null'), ref1);
    executeAction(charIDToTypeID('slct'), desc1, DialogModes.NO);
   
}
tyr

Hide/open UI windows with JS

Post by tyr »

Interesting thing: this script seem to work only in Photoshop Extended (I've tried CS6 Ext/Reg and CS5 Ext). Is there a significant difference in Photoshop Extended / regular Photoshop in terms of scripting?
undavide

Hide/open UI windows with JS

Post by undavide »

Hello,
is there any comprehensive list of menuID?
I've tried to convert to JS a simple action, including a zoom to fit - this line let me think that it can be implemented as a runMenuItem():

Code: Select allref1.putEnumerated(PSClass.MenuItem, PSType.MenuItem, PSEnum.FitOnScreen);

From which I derive (in XBytor code) that the needed TypeID is "FtOn".
Conversely, there are other commands that appears to need more Action Manager code - so I assume they can't be used as runMenuItem params.
I know that many of the PS menu commands can be used via DOM, I was just wondering if there's a limitation in runMenuItem and how to generate the full list of menuID.
Thanks!

Davide
Mike Hale

Hide/open UI windows with JS

Post by Mike Hale »

I don't know of an official list of menuItem IDs. Or how one would generate a list without manually running every menu item. Even then the list would vary some from version to version.

I think( I could be wrong I have not fully tested ) runMenuItem() will only work with menuItems that have a reference to the menu class. As inCode: Select allvar desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Mn  " ), charIDToTypeID( "MnIt" ), charIDToTypeID( "FtOn" ) );// menuClass, menuType, menuID
desc.putReference( charIDToTypeID( "null" ), ref );
executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
References to other classes, even those menuItems that don't require a reference such as 'undo', will not run using runMenuItem().
Sherlock_Holmes
Posts: 1
Joined: Fri Feb 05, 2021 8:52 pm

Re: Hide/open UI windows with JS

Post by Sherlock_Holmes »

Is there any solution to hide all panels at once in Photoshop?
I mean like when you press TAB in photoshop.
Also I thought that I use a code like "sendkey TAB", but I couldn't find any code for that.

Anyone help please?
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Hide/open UI windows with JS

Post by Kukurykus »

Code: Select all

togglePalettes()