I create some MenuItems with associated ScriptMenuAction in Design.
I use 2 events on these ScriptMenuActions : “beforeDisplay” and “onInvoke”.
The “beforeDisplay” event can be useful to check if all conditions are met for the menu to be enabled (if not then it will be grayed out).
The typically use case is to check if there is an active document.
With UXP it seems that the menu is displayed before the end of the execution of the event handler so the “enabled” property is not set before the menu is shown.
Actually I think this is a bug, the “beforeDisplay” event handler should be completely executed before the menu appears (like with JSX).
It seems the event handler is actually executed but maybe in a asynchronous way…?
I tried this in InDesign 2025 and found the following trap.
InDesign needs to reload the Submenu once to reflect ScriptMenuAction’s enabled in InDesign’s UI.
It seems that the appearance of enabled is reflected in the UI when the MenuItem is reloaded. For example, if it is reloaded by removing focus from InDesign and re-focusing it, or by clicking on the root Submenu of the ScriptMenuAction, it will look correct.
We need to remove surely the event listeners added to ScriptMenuAction before reloading the plugin/script.
Even if you rewrite the program content and reload it, the old event listeners will remain and work unless you remove them yourself or quit InDesign. That can cause unintended behavior.
It is especially easy to forget to remove them when reloading plugins in the Adobe UXP Developer Tools. Be careful.
Incidentally, I have withheld the plugin from the public because I could not achieve reliable removal of the menu. The report is here.