1 Reply Latest reply on May 19, 2009 6:00 AM by Thomas B. Nielsen

    Sub Menu Creation

    Rajeev Kumar MIL

      Dear All,

      Please see below the source code. It is working fine, but I want to add one sub menu in "Window" or in any default menu supported by InDesign.

      ------------------------------------------------------------------------------------------ ---------------

      var myMe = app.menus.item("$ID/Main").submenus.add("Test");

       

      myMe.remove();
      var mySSA= app.scriptMenuActions.add("123");
      var mySSM = app.menus.item("$ID/Main").submenus.add("Test");
      var myEL = mySSA.eventListeners.add("onInvoke", function(){
            subs();
            });
      function subs()
      {
            alert("Selction is: ",  "Test");
            }
      var mySSM = mySSM.menuItems.add(mySSA);
      ----------------------------------------------------------------------------------------- ------------------------------

      Regards,

      Rajeev

        • 1. Re: Sub Menu Creation
          Thomas B. Nielsen Level 3

          Modified from the javascript examples:

          #targetengine "session"
          //MakeScriptMenuAction.jsx
          //An InDesign CS3 JavaScript
          //
          //Adds a menu at the end of the main menu bar.
          var mySampleScriptAction = app.scriptMenuActions.add("Display Alert");
          var myEventListener = mySampleScriptAction.eventListeners.add("onInvoke", myFunction, false);
          //If the submenu "Script Menu Action" does not already exist, create it.
          //You might have to force InDesign to redraw the menu (by switching
          //out of the application and back again) to make the menu item appear.
          try{
              var mySampleScriptMenu = app.menus.item("$ID/Main").submenus.item("Window").submenus.item("Script Menu Action");
              mySampleScriptMenu.title;
          }
          catch (myError){
              var mySampleScriptMenu = app.menus.item("$ID/Main").submenus.item("Window").submenus.add("Script Menu Action");
          }
          var mySampleScriptMenuItem = mySampleScriptMenu.menuItems.add(mySampleScriptAction);
          function myFunction(){
              alert("This menu item was added by a script.");
          }

           

           

          And to clean up again:

          #targetengine "session"
          app.scriptMenuActions.everyItem().remove();
          try{
              var mySampleScriptMenu = app.menus.item("$ID/Main").submenus.item("Window").submenus.item("Script Menu Action");
              mySampleScriptMenu.remove();
          }
          catch (myError){
              alert("Could not remove menu");
          }