5 Replies Latest reply on Sep 5, 2008 2:51 AM by (D_Bennett)

    Adding panel with Javascript?


      I've written a number of script add-ons for InDesign CS2 and managed to get them installed as menu items. But what I'd really like to do is create a new panel with buttons to activate the scripts inside it. Is there any way I can do this with Javascript? (It needs to use JS as the scripts are used on Macs and PCs).

      Thanks for any help in advance!
        • 1. Re: Adding panel with Javascript?
          Loic.Aigon Adobe Community Professional
          panels deal with scriptUI in CS3 but for the few I tried to use panels I never got anything else than a error. I don't think you can get a panel in the cs2 version.

          Give yourself a try here :

          • 2. Re: Adding panel with Javascript?
            Level 1
            Ah OK, many thanks. I'll just use the Scripts panel instead!
            • 3. Re: Adding panel with Javascript?
              Dave Pepper
              I've got a question for D Bennet,

              You mentioned that you were able to create menu items using script add-ons. How do you create menu items using script add-ons? Also, is it possible to create entirely new menus?
              • 4. Re: Adding panel with Javascript?
                Level 1
                Hi David Pepper,

                It is possible to create both menu items and new menus in InDesign CS3. Take a look at the Menus chapter in the InDesign CS3 Scripting Guide.


                • 5. Re: Adding panel with Javascript?
                  Level 1
                  Indeed. This is the code I used, adapted from having found it elsewhere on the net. It doesn't appear to work in CS2, though; CS2 seems to dislike the "targetengine" which sets these things to run permanently in the background.

                  // MenuInst.jsx
                  // An InDesign JavaScript
                  @@@BUILDINFO@@@ "MenuInst.jsx" 1.0.0 1-September-2008
                  // Installs menu items.

                  // File needs to get dropped into the startup scripts directory

                  #targetengine "session"

                  // Path to where the scripts are being installed
                  var setpath = "~/Library/Preferences/Adobe InDesign/Version 5.0 ME/Scripts/Scripts Panel/";

                  var myScript1 = new File(setpath + "ScriptName.jsx");
                  var myScriptAction1 = app.scriptMenuActions.add("Menu Text");
                  var myEventListener1 = myScriptAction1.eventListeners.add("onInvoke", myScript1, false);

                  var myScript2 = new File(setpath + "ScriptName2.jsx");
                  var myScriptAction2 = app.scriptMenuActions.add("Menu Text 2");
                  var myEventListener2 = myScriptAction2.eventListeners.add("onInvoke", myScript2, false);

                  var myScript3 = new File(setpath + "ScriptName3.jsx");
                  var myScriptAction3 = app.scriptMenuActions.add("Menu Text 3");
                  var myEventListener3 = myScriptAction3.eventListeners.add("onInvoke", myScript3, false);

                  var myScript4 = new File(setpath + "ADifferentMenu.jsx");
                  var myScriptAction4 = app.scriptMenuActions.add("Other Menu Text");
                  var myEventListener4 = myScriptAction4.eventListeners.add("onInvoke", myScript4, false);

                  var myScriptMenu = app.menus.item("$ID/Main").submenus.item("First Menu");
                  catch (myError){
                  var myScriptMenu = app.menus.item("$ID/Main").submenus.add(First Menu");

                  var myScriptMenu2 = app.menus.item("$ID/Main").submenus.item("Second Menu");
                  catch (myError){
                  var myScriptMenu2 = app.menus.item("$ID/Main").submenus.add("Second Menu");

                  var myScriptMenuItem1 = myScriptMenu.menuItems.add(myScriptAction1);
                  var myScriptMenuItem2 = myScriptMenu.menuItems.add(myScriptAction2);
                  var myScriptMenuItem3 = myScriptMenu.menuItems.add(myScriptAction3);
                  var myScriptMenuItem4 = myScriptMenu2.menuItems.add(myScriptAction4);