Close / hide the panel in uxp

Thank you for the advice, the script works perfectly this way!


const core = require('photoshop').core;
const { executeAsModal } = require("photoshop").core;


async function getCommandState(commandId) {
    const descriptor = {
        _obj: 'uiInfo',
        _target: {
            _ref: 'application',
            _enum: 'ordinal',
            _value: 'targetEnum',
        },
        command: 'getCommandEnabled',
        commandID: commandId,
    };

    const result = await require('photoshop').action.batchPlay([descriptor], {});
    return result[0].result;
}


async function toggleRetouchPanel() {
    const batchCommands = {
        _obj: "get",
        _target: [
            {
                _property: "menuBarInfo"
            },
            {
                _ref: "application",
                _enum: "ordinal",
                _value: "targetEnum"
            }
        ],
    };

    let applicationState = await require('photoshop').action.batchPlay([batchCommands], {});
    let pluginsMenu = applicationState[0].menuBarInfo.submenu.find(menu => menu.name === core.translateUIString("$$$/Menu/Plugins"));
    let retouchMenu = pluginsMenu.submenu.find(menu => menu.title === "retouch");

    if (retouchMenu) {
        let retouchMenuItem = retouchMenu.submenu.find(item => item.title === "Retouch");
        if (retouchMenuItem) {
            
                await getCommandState(retouchMenuItem.command);
                console.log(`Executing Command ID: ${retouchMenuItem.command}`);
                await core.performMenuCommand({ commandID: retouchMenuItem.command });
        }
    } else {
        console.log("Retouch menu not found.");
    }
}


document.getElementById("showRetouchPanel").addEventListener('click', async () => {
    await executeAsModal(() => toggleRetouchPanel(), { "commandName": "Show Retouch Panel" });
});


2 Likes