I did try running the code you gave as-is and it didn’t seem to work for me.
also make sure that
checked
is returning the correct value. strangely in my tests sometimes it reported the opposite of visible state.
I’m experiencing this too. It’s really strange. I got the code to work… kind of. But It’s not reliable.
If I disable extras and then immediately go to the view menu - it will still show extras as enabled.
But if I click anywhere in the document or change tools and then go back to the view menu, it shows extras disabled. The same behavior occurs if I enable extras. For some reason, the change doesn’t update/propagate immediately.
It’s as if I need to force a refresh of the application “state” somehow after calling core.performMenuCommand({ commandID: 3500 });
Anyway, here’s my half-working code:
const { executeAsModal } = require("photoshop").core;
const { batchPlay } = require("photoshop").action;
const app = require('photoshop').app;
const core = require('photoshop').core;
async function showExtras(toggle) {
const batchCommands = {
_obj: "get",
_target: [
{
_property: "menuBarInfo"
},
{
_ref: "application",
_enum: "ordinal",
_value: "targetEnum"
}
],
};
let state = (await require('photoshop').action.batchPlay([batchCommands], {}));
let viewMenu = (state[0].menuBarInfo.submenu.find((m) => m.name == 'View'));
let extrasMenu = (viewMenu.submenu.find((m) => m.name == 'Extras'));
let extrasIsChecked = extrasMenu.checked;
if (extrasIsChecked != toggle) {
core.performMenuCommand({ commandID: 3500 });
}
}
document.getElementById("btnDisableExtras").addEventListener('click', async () => {
await showExtras(false);
});
document.getElementById("btnEnableExtras").addEventListener('click', async () => {
await showExtras(true);
});
If anyone knows what the problem is, a solution would be greatly appreciated!
Jay
Edit
Here’s a screen recording of what I’m talking about with regards to the performMenuCommand
not working immediately: