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

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.

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().