15 Replies Latest reply on Mar 20, 2014 6:49 AM by Laubender

    How to find a non-localized Menu name

    TᴀW Adobe Community Professional & MVP

      This is in answer to Uwe's question in a different thread, but I think it's worthy of a new thread.

      A search in the forum for "findKeyStrings" brings up a couple of useful, old, threads, too, but nothing conclusive as far as I could tell.

       

      The issue is, how to find the non-localized name of any of the menus in InDesign -- so that our scripts work in all localized versions.

       

      In the documentation, it says to use findKeyStrings(), for example: app.findKeyStrings("Window"). Somtimes this works, sometimes it returns an empty string, and sometimes you think it works but it's actually returning the non-localized string of something completely different that is also known by the same name.

       

      The thing is, that in Windows (and not Macs), you can access any menu item by pressing the Alt key. This causes an underline to appear underneath one of the letters in the menu name. Pressing that letter invokes the menu item.

       

      When creating your own menu names, you can choose the shortcut key by adding & to the menu name string: "My &New Menu" will mark the N as being the shortcut key to press when Alt is pressed first.

       

      When using findKeyStrings to find the non-localized name of a menu, it seems to be important, both on Windows and Mac, to include that &. For instance, app.findKeyStrings("View") on an English install of InDesign returns a blank string, but app.findKeyStrings("&View") returns the correct answer: $ID/&View, which will work in all language versions of InDesign. It is truly bizzare that the non-localized, universal name of the menu includes an & in it! Only Adobe can tell us what they were thinking when they did it that way!

       

      The question Uwe asked, as I understood it, is how you can know what the menu name is on a Mac so as to find the non-localized string. (On Windows it's easy: Just press the Alt key, and whatever letter in the menu name is underlined, add the & there in the menu name; that is how I was able to find &View.) There are two answers:

       

      (1) Ask someone who's got Windows!

       

      (2) I would suggest simply trying an & before each and every letter and seeing what you get. So for example, "Open Recent" in German is, apparently, "Zuletzt verwendete Datei öffnen". So to get the correct non-localized name ("$ID/Open &Recent"), simply add & before each letter in turn in the German version (including before the first letter, which is most common) until you get something other than a blank string.

       

      Perhaps someone (@Uwe?) with a German install of InDesign on a Mac can confirm that doing (2) with app.findKeyStrings("&Zuletzt verwendete Datei öffnen") etc. does eventually give the correct "$ID/Open &Recent"?

       

      Ariel

        • 1. Re: How to find a non-localized Menu name
          Laubender Adobe Community Professional & MVP

          @Ariel – thank you for opening this thread.

           

          "Zuletzt verwendete Datei öffnen" ("Open Recent") is a mystery to me. And is remaining one when used with app.findKeyStrings().

          It will return "undefined" when used with this method (German InDesign CS5.5 v7.5.3 on Mac OSX 10.6.8).

           

          Even with the added "&" at the beginning of the German localized string ( your suggestion in (2) ).

           

          I tried other menus like "Dokumentvorgaben" that also have a sub-menu (in case that was the culprit) with app.findKeyStrings(), but that orderly returned the right string array:

           

          "$ID/DocGSEUIDialogTitle"

           

          Uwe

          • 2. Re: How to find a non-localized Menu name
            Peter Kahrel Adobe Community Professional & MVP

            Thanks, Ariel, nice round-up of the problem. The following script implements your step 2: add an & in a position, try if app.findKeyStrings(string) returns something.

             

             

            s = 'Open Recent';
            n = 0;
            str = insertAmpersand (s, n);
            
            while (app.findKeyStrings(str) == "" && n < s.length) {
                n = n+1;
                str = insertAmpersand (s, n);
            }
            
            $.writeln (str)
            
            function insertAmpersand (str, pos) {
                if (pos == 0) return '&'+str;
                if (pos == str.length) return str;  // Not all names contain an &
                return str.slice(0,pos) + '&' + str.slice(pos);
            }
            

             

            Peter

            • 3. Re: How to find a non-localized Menu name
              Peter Kahrel Adobe Community Professional & MVP

              Uwe,

               

              Maybethe o+umlaut is the problem. If app.findKeyStrings() returns undefined, then that string isn't used. I've no idea how accented letters are represented in menu names though.

               

              P.

              • 4. Re: How to find a non-localized Menu name
                Laubender Adobe Community Professional & MVP

                @Peter – yes, I thought about that, but other menus with umlauts will return fine.

                 

                Like "Öffnen..." ("Open..."):

                 

                app.findKeyStrings("Öffnen...");
                

                 

                returns:

                 

                "$ID/kPMOpenDocTextKey"
                

                 

                 

                Uwe

                • 5. Re: How to find a non-localized Menu name
                  Peter Kahrel Adobe Community Professional & MVP

                  That's odd indeed.

                   

                  We should keep in mind that app.findKeyStrings can return an array of values. For instance, app.findKeyStrings ('Save') returns this:

                   

                  $ID/Save

                  $ID/kUpdateProfile

                  $ID/SaveXRefFormat

                  $ID/kSaveSecurity

                  $ID/kAnimationUISavePresetMenuItem

                  $ID/kSave

                   

                  P.

                  • 6. Re: How to find a non-localized Menu name
                    Laubender Adobe Community Professional & MVP

                    @Peter and @Ariel – ah. I think I have found a hint.

                    We could look up the localized string of the menu title. Not its name, its title!

                     

                    Here an example for the menu "Paste In Place" in my German UI:

                     

                    ({name:"An Originalposition einfügen", title:"An &Originalposition einfügen", area:"Bearbeiten-Menü", enabled:true, checked:false, id:273, label:"", parent:resolve("/"), index:15})

                     

                    Uwe

                    • 7. Re: How to find a non-localized Menu name
                      Laubender Adobe Community Professional & MVP

                      Peter wrote:

                      We should keep in mind that app.findKeyStrings can return an array of values.

                       

                      @Peter – of course. The array will be constructed out of all strings that resemble "Save" in the UI. And these are a lot scattered all over the place ;-)

                       

                      Uwe

                      • 8. Re: How to find a non-localized Menu name
                        Laubender Adobe Community Professional & MVP

                        Oh, and the "&" sign could be everywhere in the title string:

                         

                        Example: "New Window"

                         

                        ({name:"Neues Fenster", title:"Neues Fens&ter", area:"Fenster-Menü:Anordnen", enabled:true, checked:false, id:258, label:"", parent:resolve("/"), index:1})

                         

                        Uwe

                        • 9. Re: How to find a non-localized Menu name
                          Peter Kahrel Adobe Community Professional & MVP

                          Nice one, Uwe. Another script made totally unnecessary:)

                           

                          So what does this line return on your computer:

                           

                          app.menuActions.item("Zuletzt verwendete Datei öffnen").title

                           

                          Peter

                          • 10. Re: How to find a non-localized Menu name
                            TᴀW Adobe Community Professional & MVP

                            Even with the added "&" at the beginning of the German localized string ( your suggestion in (2) ).

                             

                            Suggestion (2) involves placing the ampersand before each letter of the localized name in turn and trying findKeyStrings on that. So you would try:

                             

                            &Zuletzt verwendete Datei öffnen

                            Z&uletzt verwendete Datei öffnen

                            Zu&letzt verwendete Datei öffnen

                            Zul&etzt verwendete Datei öffnen

                            Zule&tzt verwendete Datei öffnen

                            Zulet&zt verwendete Datei öffnen

                             

                            etc. until you find something.

                             

                            Peter's function makes this very easy. However, in your later post it seems like you've found a much better way.

                            • 11. Re: How to find a non-localized Menu name
                              TᴀW Adobe Community Professional & MVP

                              Laubender wrote:

                               

                              @Peter and @Ariel – ah. I think I have found a hint.

                              We could look up the localized string of the menu title. Not its name, its title!

                               

                              Here an example for the menu "Paste In Place" in my German UI:

                               

                              ({name:"An Originalposition einfügen", title:"An &Originalposition einfügen", area:"Bearbeiten-Menü", enabled:true, checked:false, id:273, label:"", parent:resolve("/"), index:15})

                               

                              Uwe

                               

                              Looks like you've found the answer! To get the non-localized string

                               

                              (1) Identify the menu you're looking for in your localized version.

                              (2) Do: app.findKeyStrings(myMenu.title)

                               

                              Ariel

                              • 12. Re: How to find a non-localized Menu name
                                Laubender Adobe Community Professional & MVP

                                @Ariel – I'm at it, just not finished testing, because using Peter's script with adding the "&" will crash my InDesign CS5.5 every time I use it with this "Zuletzt verwendete Datei öffnen".  ;-)

                                 

                                So I go a different route…

                                You hear from me after lunch. :-)

                                 

                                Uwe

                                • 13. Re: How to find a non-localized Menu name
                                  Laubender Adobe Community Professional & MVP

                                  @Ariel – ok. Before having lunch ;-)

                                   

                                  The following is no surprise:

                                   

                                  var myTitle = app.menus.item("$ID/Main").submenus.item("$ID/&File").submenus.item("$ID/Open &Recent").title;
                                  //Result: "Z&uletzt verwendete Datei öffnen"
                                  
                                  app.findKeyStrings(myTitle);
                                  //Result: "$ID/Open &Recent" 
                                  //No surprise here: 
                                  //I asked explicitly for "$ID/Open &Recent" and the answer is of course "$ID/Open &Recent".
                                  

                                   

                                   

                                  But how can I know "$ID/Open &Recent" in advance or the exact title string "Z&uletzt verwendete Datei öffnen" in my localized version?

                                   

                                  Let's try with the id of the menu:

                                   

                                  //THAT WILL CRASH MY InDesign CS5.5 v7.5.3, not always, but it did:
                                  
                                  var myID = app.menus.item("$ID/Main").submenus.item("$ID/&File").submenus.item("$ID/Open &Recent").id;
                                  myID;
                                  

                                   

                                  Error: Object does not support property or method id

                                   

                                  Maybe a bug with my InDesign version.

                                   

                                  Let's see what's in the bag:

                                   

                                  var myMenu = app.menus.item("$ID/Main").submenus.item("$ID/&File").submenus.item("$ID/Open &Recent");
                                  
                                  for(x in myMenu){
                                      $.writeln(x+"\t"+myMenu[x]);
                                      };
                                  
                                  /*
                                  name    Zuletzt verwendete Datei öffnen
                                  title    Z&uletzt verwendete Datei öffnen
                                  isValid    true
                                  parent    [object Submenu]
                                  index    1
                                  properties    [object Object]
                                  events    [object Events]
                                  eventListeners    [object EventListeners]
                                  menuElements    [object MenuElements]
                                  submenus    [object Submenus]
                                  menuItems    [object MenuItems]
                                  menuSeparators    [object MenuSeparators]
                                  isValid    true
                                  
                                  */
                                  

                                   

                                  Ok. Then the title route will work.

                                  A for loop through all menus should reveal, that there are menus (at least one is!) without id.

                                   

                                  Uwe

                                  • 14. Re: How to find a non-localized Menu name
                                    TᴀW Adobe Community Professional & MVP

                                    Let's keep it simple.

                                     

                                    (1) First get a reference to the menu you're after. There are a few ways of doing this: (a) If you know the name of the parent menu, you could cycle through the submenus by index:

                                     

                                    myMenu = app.menus.item("$ID/Main");

                                    for (i = 0; i < myMenu.submenus.length; i++){

                                         $.writeln(myMenu.submenus[i].title);

                                    }

                                     

                                    (b) but a more direct method should be possible: Simply type in the localized name of the menu you want, e.g.:

                                     

                                    s = app.menus.item("$ID/Main").submenus.item("File").submenus.item("Open Recent")

                                     

                                    where "File" and "Open Recent" should be replaced with the localized names you see in the UI in German.

                                     

                                    (2) Now to find the non-localized name, tag on .title to the end, as you discovered:

                                    s.title

                                     

                                    I don't think it is necessary to use the id property at all.

                                     

                                    Ariel

                                    • 15. Re: How to find a non-localized Menu name
                                      Laubender Adobe Community Professional & MVP

                                      @Ariel – thank you again…
                                      Yeah. That should be doable.

                                       

                                      I did mention all my steps in answer #13, because I was a little shocked finding a menu item without an id property.

                                       

                                      But this should be no surprise after looking into the DOM documentation again:

                                       

                                      app.menu has no property id, menuActions have ;-)

                                       

                                      Just to quote documentation:

                                       

                                      Menu

                                      title | string | readonly

                                      The name of the MenuAction for display in the user interface. The title includes any ampersand characters (&), which are used to tell the Windows OS to underline the following character in the name for use with the Alt key to navigate to a menu item. Double ampersands are used to display an actual ampersand character in the name. The Mac OS ignores and removes the extra ampersand characters.

                                       

                                       

                                      Uwe