• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
7

Completely remove submenu added by script

Community Expert ,
Aug 22, 2023 Aug 22, 2023

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.

submenu.png

 

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:

  • InDesign 2023 (18.5.0.57)
  • macOS 12.6.7
TOPICS
Scripting

Views

430

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 23, 2023 Aug 23, 2023

Copy link to clipboard

Copied

Try removing InDesign's preferences (hold down Cmnd/Ctrl+Alt+Del while starting InDesign. I think that will work.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 23, 2023 Aug 23, 2023

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 23, 2023 Aug 23, 2023

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 23, 2023 Aug 23, 2023

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 23, 2023 Aug 23, 2023

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 23, 2023 Aug 23, 2023

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 23, 2023 Aug 23, 2023

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 23, 2023 Aug 23, 2023

Copy link to clipboard

Copied

Report that the same problem occurred in the English version.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 23, 2023 Aug 23, 2023

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:

 

PeterKahrel_0-1692804541193.png

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 23, 2023 Aug 23, 2023

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines