16 Replies Latest reply on Mar 15, 2010 2:04 PM by Steven..

    [JS] Problem in findKeyString and menuAction

    Loic.Aigon Adobe Community Professional

      Hi,

       

      I read the scripting guide and try to apply that snippet :

       

      var myString = "";
      
      var myMenuAction = app.menuActions.item("Convert to Note");
      
      var myKeyStrings = app.findKeyStrings(myMenuAction.name);
      
      if(myKeyStrings.constructor.name == "Array"){
      
      for(var myCounter = 0; myCounter < myKeyStrings.length; myCounter ++){
      
      myString += myKeyStrings[myCounter] + "\r";
      
      }
      
      }
      
      else{
      
      myString = myKeyStrings;
      
      }
      
      alert(myString);
      

       

       

      I want to get the independant locale string for my french "Document..." command (New Document basically). But if I replace "Convert to Note" by "Document...", the script just prints an empty string.

      I am not sure at all but all my attempts to findKeyString with strings containing ellipsis just fail.

       

      Furtherly I want to add a eventListener on that menu but I think this post from Kasyan will be instructive enough.

      The problem is start, at the very beginning, I can't get acces to the native $ID/xxx string for the New Document command :-S

      http://forums.adobe.com/message/1107494#1107494

       

      Any hint ?

       

      Thanks for all of you guys helping me through years.

       

      Loic

        • 1. Re: [JS] Problem in findKeyString and menuAction
          John Hawkinson Level 5

          Minor notes:

           

          Instead of

          for(var myCounter = 0; myCounter < myKeyStrings.length; myCounter ++){
          myString += myKeyStrings[myCounter] + "\r";
          }

          You can use

          myString = myKeyStrings.join("\r");
          

           

          In my experience commands with elipsis points actually have 3 consecutive ASCII periods in the name, rather than an ellipsis character.

          • 2. Re: [JS] Problem in findKeyString and menuAction
            Marc Autret Level 4

            Hi Loic,

             

            This should work:

             

            // Get the File / New / Document... menu action
            var mnaNew = app.menuActions.item("$ID/&Document...");
            
            // Invoke the menu action:
            mnaNew.invoke();
            

             

            If you need to get the menu item itself, you may also browse the menu hierarchy this way:

             

            var mnuNew = app.menus.item("$ID/Main").
                 submenus.item("$ID/&File").
                 submenus.item("$ID/&New").
                 menuItems.item("$ID/&Document...");
            
            // Sample:
            alert( mnuNew.associatedMenuAction.name );
            

             

            @+

            Marc

            • 3. Re: [JS] Problem in findKeyString and menuAction
              John Hawkinson Level 5

              Incidently,

              app.menuActions.item("$ID/Document...")
              

              works just as well as

              app.menuActions.item("$ID/&Document...")
              

              and presumably omitting the & is more robust (if anything changes down the line).

              1 person found this helpful
              • 4. Re: [JS] Problem in findKeyString and menuAction
                Loic.Aigon Adobe Community Professional

                Hi John,

                 

                Thanks a lot for your proposal but it didn't solve the case. I have seen and tried yet the join("\r") trick viewed on Marc website and got no result :-(

                I type 3 perios but it didn't change the result.

                 

                Thanks a lot anyway.

                 

                Loic

                • 5. Re: [JS] Problem in findKeyString and menuAction
                  Loic.Aigon Adobe Community Professional

                  Hi Marc,

                   

                  Thanks a lot, it worked but I can't understand why I couldn't get the non locale string based on findKeyString method with "Document..." as string.

                  It's nice to know the good command but I would have enjoyed to be able to get the result through the findKeyString method.

                   

                  Thanks a lot anyway.

                   

                  Loic

                  • 6. Re: [JS] Problem in findKeyString and menuAction
                    Loic.Aigon Adobe Community Professional

                    Hi John, you are right, it works with or without the ampersand.

                     

                    Thanks Loic

                    • 7. Re: [JS] Problem in findKeyString and menuAction
                      Harbs. Level 6

                      No. Stick with the ampersand -- that's the correct one. There might be 

                      languages where "&Document..." and "Document..." are translated 

                      differently, and then the script will fall flat on its face without 

                      any apparent reason! (from experience with a similar type of string...)

                       

                      Harbs

                      • 8. Re: [JS] Problem in findKeyString and menuAction
                        John Hawkinson Level 5

                        Can you support that, Harbs? findKeyStrings() doesn't return the ampersands, does it?

                        • 9. Re: [JS] Problem in findKeyString and menuAction
                          Harbs. Level 6

                          Hi John,

                           

                          I wrote that without checking "Document".

                           

                          Very odd...

                           

                          $.writeln(app.menus.item("Main").submenus.item("&File").submenus.item("&New").menuElements.item(0).title);

                          gets you: "&Document..."

                           

                          but app.findKeyStrings("&Document...") gets you: "$ID/Document..." instead of "$ID/&Document..."

                           

                          This goes against what I've seen with every other menu item that I've ever checked. It strikes me as a bug. I'll try to find out...

                           

                          Harbs

                          1 person found this helpful
                          • 10. Re: [JS] Problem in findKeyString and menuAction
                            Loic.Aigon Adobe Community Professional

                            Ok Harbs,

                             

                            Thanks a lot, it means that To get "$ID/Document...", I needed to add an ampersand in front of my string to get it non localized.


                            I would be nice this is documented in the scripting guide (or maybe it is and I didn't see it).

                             

                            Thank you a lot Harbs, I see clearer now.

                             

                            Loic

                            • 11. Re: [JS] Problem in findKeyString and menuAction
                              John Hawkinson Level 5

                              Wait...what's an example of a menu item where findKeyStrings() returns an &?    

                              • 12. Re: [JS] Problem in findKeyString and menuAction
                                Harbs. Level 6

                                How many would you like?

                                 

                                $.writeln(app.findKeyStrings("&New"));

                                $.writeln(app.findKeyStrings("&File"));

                                $.writeln(app.findKeyStrings("&Layout"));

                                $.writeln(app.findKeyStrings("&Edit"));

                                $.writeln(app.findKeyStrings("&Open..."));

                                 

                                and about any other one you'd like to try...

                                 

                                Harbs

                                • 13. Re: [JS] Problem in findKeyString and menuAction
                                  John Hawkinson Level 5

                                  Oh, this is fascinating. It appears to, most of the time, return an & but only if you give it an & as input.

                                   

                                  So, for instance:

                                   

                                  function check(s) {
                                       $.writeln("for "+s+"\n"+
                                       "no-&\t" + app.findKeyStrings(s).join("\n\t")+"\n"+
                                       "&\t" + app.findKeyStrings("&"+s).join("\n\t")+
                                       "\n");     
                                       }
                                  
                                  check("Document");
                                  check("New");
                                  check("File");
                                  check("Layout");
                                  check("Edit");
                                  check("Open...");
                                  

                                   

                                  Produces:

                                  for Document
                                  no-&    $ID/TV Document
                                          $ID/DE_Document
                                          $ID/Document
                                          $ID/kDocument
                                          $ID/kPMDocumentTextKey
                                          $ID/kPMWOpenDocumentWidgetTextLineIIKey
                                          $ID/kPMWNewDocumentWidgetTextLineIIKey
                                  &
                                  
                                  for New
                                  no-&    $ID/kPMWNewDocumentWidgetTextLineIKey
                                          $ID/Structure_NewFlyout
                                  &       $ID/&New
                                  
                                  for File
                                  no-&
                                  &       $ID/&File
                                  
                                  for Layout
                                  no-&    $ID/0x58900kS_LayoutStr [NT]
                                          $ID/LayoutTabName
                                          $ID/0x58900kS_LayoutKey
                                          $ID/FS Layout
                                          $ID/Layout
                                  &       $ID/&Layout
                                  
                                  for Edit
                                  no-&    $ID/Structure_Edit
                                          $ID/Edit
                                  &       $ID/&Edit
                                          $ID/#DIALOG_HyperlinkEdit
                                  
                                  for Open...
                                  no-&    $ID/kPMOpenDocTextKey
                                  &       $ID/Open...
                                          $ID/&Open...
                                  

                                   

                                  So, in many cases, findKeyStrings() with an & and without an & both return their respective & and &-less versions of $ID/foo and $ID/&foo. But in some cases, without an & returns wrong unhelpful keystrings that seem to substring match foo. And in other cases, & seems required.

                                   

                                  I don't find any support here for the idea that using & is better than not. Obviously in some cases you are required to use it (File) and in other cases you are required not to use it (Document), and this seems like it must be a bug because who the heck would figure it out,..

                                  • 14. Re: [JS] Problem in findKeyString and menuAction
                                    John Hawkinson Level 5

                                    This one is interesting, too. I'm doing this in CS3 on a Mac, I wouldn't be surprised of you got diferent results on a PC, given that the & is meaningless on the Mac. Anyhow, given:

                                     

                                    var ampname=0, amptitle=0, disagree=0,noamp=0,yesamp=0 ;
                                    
                                    for (i=0; i<app.menus.length; i++) {
                                         var m = app.menus[i];
                                         
                                         if (m.title.match(/&/)) amptitle++;
                                         if (m.name.match(/&/)) ampname++;
                                         
                                      if (m.title != m.name) disagree++;
                                      noamp += app.findKeyStrings(m.name).length;
                                      yesamp += app.findKeyStrings("&"+m.name).length;
                                    }
                                    
                                    $.writeln("Over "+app.menus.length+" top-level menus, \n"+
                                    +disagree+" disagree on their name and title.\n"+
                                    ampname+" have & in their names\n"+
                                    amptitle+" have & in their titles\n"+
                                    noamp+" translated strings are found for &-less finds\n"+
                                    yesamp+" translated strings are found for &-ful finds");
                                    

                                    I get:

                                    Over 117 top-level menus, 
                                    6 disagree on their name and title.
                                    2 have & in their names
                                    6 have & in their titles
                                    112 translated strings are found for &-less finds
                                    0 translated strings are found for &-ful finds
                                    undefined
                                    

                                    The ones that disagree are things like:

                                    TITLE Bulleted && Numbered Lists Metacharacter Menu NAME Bulleted & Numbered Lists Metacharacter Menu
                                    

                                    which is clearly some quoting thing.

                                     

                                    Message was edited by: John Hawkinson; fixed missing .length on yesamp+= line. Does not affect output.

                                    • 15. Re: [JS] Problem in findKeyString and menuAction
                                      John Hawkinson Level 5

                                      Though maybe it's more interesting to run it on menuActions instead of menus:

                                      Over 2698 top-level menusActions, 
                                      524 disagree on their name and title.
                                      6 have & in their names
                                      524 have & in their titles
                                      2527 translated strings are found for &-less finds
                                      537 translated strings are found for &-ful finds
                                      
                                      • 16. Re: [JS] Problem in findKeyString and menuAction
                                        Steven.. Level 3

                                        I have a master list for all menu key strings in csv format. It might take some time to figure whats happening, but its all there. If interested you can contact me in private.