5 Replies Latest reply on Mar 29, 2010 11:51 PM by John Hawkinson

    Submenus repeated more than once

    UDevp

      While creating own InDesign menus in CS4 using scriptmenuaction, same submenu is

      repeated thrice when placed in startup folder. Any explanation for this would be helpful.

        • 1. Re: Submenus repeated more than once
          John Hawkinson Level 5

          Once thing to note is that ScriptMenuActions (but not their placement in menus) persist across invokations of InDesign (quite nonintuitive).

           

          But aside from that hint, you really need to give us more information in order for us to help you. Post your script here.

           

          Better yet, reduce your script to the smallest example script that still demonstrates the error. This may help you find the problem on your own, but it will certainly make it easier for us to look at the script and find the problem.

          • 2. Re: Submenus repeated more than once
            UDevp Level 1

            Hi,

             

                Here is the script which I'm using,

             

                     

            var mySampleScriptAction = app.scriptMenuActions.add("Display Message");

            var myEventListener = mySampleScriptAction.eventListeners.add("onInvoke",

            function(){alert("This menu item was added by a script.");});

            try{

            var mySampleScriptMenu = app.menus.item("$ID/Main").submenus.item(

            "Script Menu Action");

            mySampleScriptMenu.title;

            }

            catch (myError){

            var mySampleScriptMenu = app.menus.item("$ID/Main").submenus.add

            ("Script Menu Action");

            }

            var mySampleScriptMenuItem = mySampleScriptMenu.menuItems.add(mySampleScriptAction);

             

               When placing the script in start up folder in CS4 or CS3 both I've checked, the submenu 'Display Message' is repeadted 3 times in InDesign. Can anyone help why this occuring?

            • 3. Re: Submenus repeated more than once
              John Hawkinson Level 5

              Well, curiously, I placed it in my User scripts Startup Scripts folder and restarted indesign 3 or 4 times and I only see 1 copy of it. Though

              the "Display Message" menu item does not work (generates a javascript error).

               

              So I suspect if you were to run

              app.menus[0].submenus.item("Script Menu Action").remove()
              

              several times it might solve your problem.

               

              But anyhow, I believe you need to checking to avoid duplicating both the ScriptMenuAction as well as duplicating the submenu itself.

              So:

              var mySampleScriptAction= app.scriptMenuActions.item("Display Message");
              if (mySampleScriptAction == null)
                mySampleScriptAction = app.scriptMenuActions.add("Display Message");
              

              (I know I'm beating a dead horse, but how can you guys keep typing "mySampleScriptAction"? Why not something nice and easy to type like "displayAction" or even "da"? I guess I just hate the "my"s. Pet peeve).

               

              You might need a similar check before adding the menuItem.

               

              Incidently, "Display Message" is not a submenu -- it is a menuItem associated with a subMenu ("Script Menu Action").

              • 4. Re: Submenus repeated more than once
                UDevp Level 1

                Well, that was the example script provided in Scripting guide

                for using script menu actions, I was just checking the working of script menu actions. I think you need tp place the script in startup scripts folder located in Common Files folder, the script doesn't show any javascript error.

                • 5. Re: Submenus repeated more than once
                  John Hawkinson Level 5

                  Both Startup Scripts folders are equivalent -- ultimately it did work for me, after I had made my suggested edits and also added #targetengine session to the top. Maybe one or both of those are not necessary.

                   

                  I think your problems arise from multiple-definition of ScriptMenuActions.