4 Replies Latest reply on Sep 28, 2011 1:17 PM by Really Randy

    Selecting a submenu item with AS (or JS)

    Really Randy Level 1

      I'm trying to invoke a submenu item from a keystroke. The item does not appear in the "Keyboard Shortcuts..." dialog. I've looked everywhere and it's just not there. It's a plugin made by Mediawide that dynamically resizes objects and pages according you my preset specs.

       

      So I decided to just write a GUI script to invoke the menu item and then assign a keystroke to the script. The script works fine when I invoke it from the finder but if I invoke the script from the ID scripts palette, it just flashes the Apple menu for a split second and that's it. That defeats the purpose of assigning a keycommand to it.

       

      I think it may have something to do with the fact that it activates "System Events" which is an outside app.

       

      Can anyone shed some light on this?

       

      Below is the script and below that, a screenshot of the menu item.

      activate application "Adobe InDesign CS4"
      
      tell application "System Events"
                tell process "Adobe InDesign CS4"
                          tell menu bar 1
                                    tell menu bar item "Window"
                                              pick
                                              tell menu 1
                                                        tell menu item "Dynamic Resize"
                                                                  pick
                                                                  tell menu 1
                                                                            pick menu item "Resize Document"
                                                                  end tell
                                                        end tell
                                              end tell
                                    end tell
                          end tell
                end tell
      end tell
      
      

      ResizeMenu.jpg

        • 1. Re: Selecting a submenu item with AS (or JS)
          Dirk Becker Level 4

          The following snippet invokes a menu item from within InDesign.

           

          (function(){

          var m = app.menus.itemByName("$ID/Main").submenus.itemByName("$ID/&File");

          // $.writeln(m.menuItems.everyItem().name);

          var mi = m.menuItems.itemByName("$ID/File Information...");

          var a = mi.associatedMenuAction;

          a.invoke();

          })();

           

          Dirk

          1 person found this helpful
          • 2. Re: Selecting a submenu item with AS (or JS)
            Really Randy Level 1

            Thank you Dirk,

            That's almost got me where I need to be. Your script to open the File Info menu works fine but unfortunately my changes broke it. (BTW, I notice That in your script you ID "File Information..." when the menu item is "File Info...".  Is there a rule somewhere regarding menu item names?)

             

            I changed the submenu item to "Window" and the itemByName to "Resize Document" but I'm still getting an error on line 5, probably because it's a submenu item as illustrated in the screenshot above. The structure is actually Main>Window>Dynamic Resize>Resize Document. I just don't know where to put the "Dynamic Resize" part of the menu structure in there.

             

            Here's what I have

             

            (function(){
            var m = app.menus.itemByName("$ID/Main").submenus.itemByName("$ID/&Window");
            // $.writeln(m.menuItems.everyItem().name);
            var mi = m.menuItems.itemByName("$ID/Resize Document");
            var a = mi.associatedMenuAction;
            a.invoke();
            })();
            
            Thanks
            RR
            
            • 3. Re: Selecting a submenu item with AS (or JS)
              Dirk Becker Level 4

              You can't make up those strings behind the "$ID/", they are lookup indexes in a string database.

              In German InDesign, the "&Window" would for example be displayed as "Fenster".

               

              Besides the submenu "Window" will have another submenu "Dynamic Resize".

               

              To find the correct string IDs for that "Resize Document" and the "Dynamic Resize" submenu, use the function

              $.writeln(app.findKeyStrings("Resize Document"));

               

              It will hopefully produce an array of candidates.

               

              As you're targeting an external plugin, the key string will be less readable with some prefix like "0x123400".

              If you can't find the key string, use that commented out line to dump out the names of all menu items.

               

              Dirk

              • 4. Re: Selecting a submenu item with AS (or JS)
                Really Randy Level 1

                Thanks for that reply. It works wonderfully for all menu items except for the ones I need. I submitted a bug report to the manufacturer of the plugin, maybe they will make their menu items visible so I can script a shortcut. I'll let you know the solution when it comes.

                 

                Thanks again.

                 

                RR