Skip to main content
Frans v.d. Geest
Community Expert
Community Expert
January 8, 2023
Answered

Scripting: add a menu item, possible?

  • January 8, 2023
  • 6 replies
  • 987 views

Dear scripters,

as InDesign later then 2019 will not install under Apple M1 ARM Windows 11 (using Parallels) and sometimes I teach only Windows users using my Mac, I wondered if there is a possibility for a start up script that adds a 'Preferences' menu at the end of the Edit menu like it is in Windows (latest item in Edit menu) so I don't have to explain that difference every to Windows users. That menu then when invoked should indeed call the Preference Window.

Note that I'm using a Dutch system, so any call could not be on the exact name.

I am no scripter so I have no idea at all if this is even possible but any suggestions or help would be very, very apreciated!

Thanks in advance 😉

This topic has been closed for replies.
Correct answer m1b

Hi @Frans v.d. Geest, I've made an attempt...

var invokePrefs = app.menuActions.itemByName("General..."),
    editMenu = app.menus[0].submenus.item("Edit"),
    newPrefsMenu = editMenu.submenus.item("Preferences");

if (newPrefsMenu.isValid) {
    newPrefsMenu.remove();
    alert('Extra Preferences Menu removed')
}

else {
    newPrefsMenu = editMenu.submenus.add("Preferences");
    newPrefsMenu.menuItems.add(invokePrefs);
    alert('Extra Preferences Menu added')
}

This should put "Preferences" at the bottom of the Edit Menu. It will have a submenu "General..." which will invoke the preferences dialog. I could add all the other submenus here if necessary. Does this help?

- Mark 

6 replies

Peter Kahrel
Community Expert
Community Expert
January 9, 2023

@Frans v.d. Geest -- When I run the script an entry 'General... (Ctrl+K)' is added, and when I click that, the Preerences menu appears with all the entries as usual. Doesn't that happen at your end? If you want 'Preferences' instead of 'General...', that requires some more work.

Frans v.d. Geest
Community Expert
Community Expert
January 9, 2023

Peter, yes it works, the fly out etc. Working great 🙂
I was just wondering if, all the rest like 'Interface' etc could also be part of the fly out, so seeing all the options in the submenu, not only General, like under the InDesign menu on the Mac. Not that it is that important, but just to see the same on Mac as under Windows, for clarity of users. 
But both scripts work, and I'm very happy with it 😉

I was just wondering (asking the impossible maybe) if that could be added,  as I am no scripter (tried to learn it a few times, but I had no flair for it...)

Peter Kahrel
Community Expert
Community Expert
January 9, 2023

Ah, you mean like in the screenshot? No, that's not possible I don't think.

 

 

Frans v.d. Geest
Community Expert
Community Expert
January 9, 2023

@Peter Kahrel  @m1b  Thank hou both, much appreciated!
Now... at the risk off overreaching.... is there a way to show all the entries besides General in that added menu...? Or am I playing with fire now 😉

Peter Kahrel
Community Expert
Community Expert
January 9, 2023

Ouch! Apologies -- It worked in my ID2022 installation because Preferences... is a valid item in one of my plug-ins, which fired up InDesign's Preferences window. Now that I tried without plug-ins I see that the menu action to use is General... So when you change '$ID/Preferences...' to '$ID/General...' it will work.

 

All this is academic, of course, because you got Mark's script to work.

 

P.

Frans v.d. Geest
Community Expert
Community Expert
January 9, 2023

Ag, thanks Peter, indeed that works. 

Peter Kahrel
Community Expert
Community Expert
January 8, 2023

Mark -- No need to add all those menu items, all you need is to place InDesign's Preferences menu item as a menuAction in the Edit menu:

 

 

(function () {
  var editMenu = app.menus.item('$ID/Main').submenus.item('$ID/Edit')
    if (!editMenu.menuItems.item('$ID/Preferences...').isValid) {
      editMenu.menuItems.add (app.menuActions.item ('$ID/Preferences...'));
    }
}());

 

 

 

Frans -- the above script adds a Preferences entry at the bottom of the Edit menu. It should work in your Dutch version (the $ID/ prefix makes the items language-independent). To remove the item, run the following script:

 

 

try {
   app.menus.item('$ID/Main').submenus.item('$ID/Edit')
     .menuItems.item ('$ID/Preferences...').remove();
} catch(_) {
}

 

 

Peter

m1b
Community Expert
Community Expert
January 8, 2023

Now that's more like it! Thanks Peter. I'm new to scripting menus and I learned a surprising large amount from your short script! 🙂

- Mark

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
January 8, 2023

Hi @Frans v.d. Geest, I've made an attempt...

var invokePrefs = app.menuActions.itemByName("General..."),
    editMenu = app.menus[0].submenus.item("Edit"),
    newPrefsMenu = editMenu.submenus.item("Preferences");

if (newPrefsMenu.isValid) {
    newPrefsMenu.remove();
    alert('Extra Preferences Menu removed')
}

else {
    newPrefsMenu = editMenu.submenus.add("Preferences");
    newPrefsMenu.menuItems.add(invokePrefs);
    alert('Extra Preferences Menu added')
}

This should put "Preferences" at the bottom of the Edit Menu. It will have a submenu "General..." which will invoke the preferences dialog. I could add all the other submenus here if necessary. Does this help?

- Mark 

Frans v.d. Geest
Community Expert
Community Expert
January 8, 2023

Thanks, going to test it as soon as I can and will let you know 😉

But looking at at it I see the 'itembyname', which I guess will only work in English versions, so I will do some 'translation' first to see it that will work...

Mike Witherell
Community Expert
Community Expert
January 8, 2023

I like that idea! 

Mike Witherell