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

Scripting: add a menu item, possible?

Community Expert ,
Jan 08, 2023 Jan 08, 2023

Copy link to clipboard

Copied

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 😉

TOPICS
Scripting

Views

260

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

correct answers 1 Correct answer

Community Expert , Jan 08, 2023 Jan 08, 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"

...

Votes

Translate

Translate
Community Expert ,
Jan 08, 2023 Jan 08, 2023

Copy link to clipboard

Copied

I like that idea! 

Mike Witherell

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 ,
Jan 08, 2023 Jan 08, 2023

Copy link to clipboard

Copied

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 

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 ,
Jan 08, 2023 Jan 08, 2023

Copy link to clipboard

Copied

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

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 ,
Jan 08, 2023 Jan 08, 2023

Copy link to clipboard

Copied

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

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 ,
Jan 08, 2023 Jan 08, 2023

Copy link to clipboard

Copied

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

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 ,
Jan 08, 2023 Jan 08, 2023

Copy link to clipboard

Copied

Well look at that! Great Peter, thanks! Once again, you are the master of scripted solutions 😉

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 ,
Jan 08, 2023 Jan 08, 2023

Copy link to clipboard

Copied

Actually Peter, I get an error with that code (the same error I got when I was experimenting myself now that I think about it). The menuAction I get isn't valid. When I run your code (with a validity check) I see the alert:

(function () {
    var editMenu = app.menus.item('$ID/Main').submenus.item('$ID/Edit')
    if (!editMenu.menuItems.item('$ID/Preferences...').isValid) {
        var menuAction = app.menuActions.item('$ID/Preferences...');
        if (menuAction.isValid)
            editMenu.menuItems.add(menuAction);
        else
            alert('menuAction isn\'t valid.');
    }
}());

I'm running ID 18.1, MacOS 13.1. Maybe a Mac problem? I'm curious to know if it works for you, @Frans v.d. Geest.

- Mark

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 ,
Jan 08, 2023 Jan 08, 2023

Copy link to clipboard

Copied

@m1b For now, after translating the menu items to Dutch, your script worked 😉

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 ,
Jan 08, 2023 Jan 08, 2023

Copy link to clipboard

Copied

Haha! That's a first! 🙂

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 ,
Jan 08, 2023 Jan 08, 2023

Copy link to clipboard

Copied

@Peter Kahrel Ah... yes, get the same: error on execute...Scherm­afbeelding 2023-01-08 om 23.57.38.png

 

 

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 ,
Jan 08, 2023 Jan 08, 2023

Copy link to clipboard

Copied

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.

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 ,
Jan 09, 2023 Jan 09, 2023

Copy link to clipboard

Copied

Ag, thanks Peter, indeed that works. 

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 ,
Jan 09, 2023 Jan 09, 2023

Copy link to clipboard

Copied

@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 😉

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 ,
Jan 09, 2023 Jan 09, 2023

Copy link to clipboard

Copied

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

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 ,
Jan 09, 2023 Jan 09, 2023

Copy link to clipboard

Copied

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

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 ,
Jan 09, 2023 Jan 09, 2023

Copy link to clipboard

Copied

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

 

PeterKahrel_0-1673268006495.png

 

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 ,
Jan 09, 2023 Jan 09, 2023

Copy link to clipboard

Copied

LATEST

Yes, like that. Just wondering, but already helped very much by what we have now 😉

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