Copy link to clipboard
Copied
I am trying to remove a submenu added to the main menu via ExtendScript.
Script to add:
app.menus[0].submenus.add('Menu from Script') ;
Script to remove:
app.menus[0].submenus.item('Menu from Script').remove() ;
In fact, I can remove it from the menu bar, but it will remain in Edit > Menu... customization screen.
To remove it, I had to manually delete the following cache file
~/Library/Caches/Adobe InDesign/Version 18.0-J/ja_JP/InDesign SavedData
What is the best way to delete it without it remaining in the menu customization screen with just for scripts?
Environment:
Copy link to clipboard
Copied
Try removing InDesign's preferences (hold down Cmnd/Ctrl+Alt+Del while starting InDesign. I think that will work.
Copy link to clipboard
Copied
I have seen in the past that menu entries created via script as somewhat sticky and is not removed even if the code creating it is removed. The only way I could figure out to get rid of it is was to trash the preferences as @Peter Kahrel mentioned.
-Manan
Copy link to clipboard
Copied
Thanks for your responses, @Peter Kahrel, @Manan Joshi.
This question is aimed at developing a well-mannered script that generates a submenu when InDesign is launched and disappears completely when it quits. Should I assume that is not possible?
Copy link to clipboard
Copied
I can't think of any way, atleast till the next restart of InDesign. Even if we think of deleting the preferences via code even then it would be a tricky one as the file would be in use by InDesign and I am not sure if it will allow us to delete or edit it via code.
-Manan
Copy link to clipboard
Copied
you should be able to do it by adding something like this to your initial script:
app.addEventListener("afterQuit", removeMenu);
where removeMenu() is your function do do this.
although, as far as I understand, your issue is with your menu staying in Menu Customization, and I also don't know why it happens.
Copy link to clipboard
Copied
Well, actually, it works ok over here: when I add a menu item it appears in the top menu and in the Menu Customisation window. Then when I remove the added item using remove(), it's removed from the menu bar and the Menu Customisation window. Not sure what's going on in your document. Maybe some corruption? Maybe try adding and removing another menu item and see whether the problem persists.
Copy link to clipboard
Copied
In my environment, even a submenu with a different name, it is increased in Menu Customisation and cannot be deleted.
Maybe there is something wrong with Japanese or other Asian language versions. I will try installing the English version.
Copy link to clipboard
Copied
Report that the same problem occurred in the English version.
Copy link to clipboard
Copied
And when you try to remove that menu item again, there's no error?
As a wild guess, maybe it has something to do with the settings of the applied workspace:
When I tried, 'Menu Customisation' was enabled, as in the screenshot. Maybe try disabling it and see what happens.
Trouble is that that state is not scriptable.
Copy link to clipboard
Copied
I get an error ReferenceError: Object is invalid. This is expected behavior, because the target submenu no longer exists.
I created a new workspace, disabled Menu Customization and tried again in English version. The result is the same: it disappears from the menu bar, but remains in Menu Customization.
Our attempts are not going smoothly...