3 Replies Latest reply: Mar 5, 2012 9:32 AM by kdeemer RSS

    Help Adding Menu Items to Bridge

    kdeemer Community Member

      I've created (modified) a couple of Bridge Scripts and finally have them working nicely. Now, I want to add a couple of Menu Commands to execute them. I tried modifying a script in the SDK, SnpAddMenuItem.jsx, which would work fine if I only had one Menu Item/Command. Here is what I have. I obviously don't understand the 'this' object or how to separate the Commands. Help much appreciated.

       

       

       

      function SnpAddMenuItem()

      {

                this.requiredContext = "\tAdobe Bridge must be running.\n\tExecute against Bridge CS5 as the target.\n";

                this.menuID = "snpAddMenuItem";

                this.menuCommandID = "snpAddMenuItemSub";

       

                $.level = 1; // Debugging level

      }

      SnpAddMenuItem.prototype.run = function()

      {

                var retval = true;

                if(!this.canRun()) {

                          retval = false;

                          return retval;

                }

          var newMenu = new MenuElement( "menu", "Scanning", "after Window", this.menuID );

          var stackCommand = new MenuElement( "command", "Gather NNYY Into Stacks", "at the end of " + this.menuID, this.menuCommandID );

          var maskCommand = new MenuElement( "command", "Process Stacks into Layers", "at the end of " + this.menuID, this.menuCommandID );

                stackCommand.onSelect = function()

                {

                          var scriptFilePath = "~/Documents/Adobe Scripts/AutostackNNYY.jsx";

               var scriptFile = new File (scriptFilePath);

               $.evalFile( scriptFile );

                }

          return retval;

                maskCommand.onSelect = function()

                {

                          var scriptFilePath = "~/Documents/Adobe Scripts/StacksToLayers.jsx";

               var scriptFile = new File (scriptFilePath);

               $.evalFile( scriptFile );

                }

                return retval;

      }

       

       

      /**

        Determines whether snippet can be run given current context.  The snippet

        fails if these preconditions are not met:

        <ul>

        <li> Must be running in Bridge

        <li> Must only be executed once in a session

        </ul>

       

        @return True if this snippet can run, false otherwise

        @type boolean

      */

      SnpAddMenuItem.prototype.canRun = function()

      {

                // Must run in Bridge

                if(BridgeTalk.appName == "bridge") {

       

                          // Stop the menu element from being added again if the snippet has already run

                          if((MenuElement.find(this.menuID)) && (MenuElement.find(this.menuCommandID)))

                          {

                                    $.writeln("Error:Menu element already exists!\nRestart Bridge to run this snippet again.");

                                    return false;

                          }

       

                          return true;

                }

       

                // Fail if these preconditions are not met. 

                // Bridge must be running,

                // The menu must not already exist.

                $.writeln("ERROR:: Cannot run SnpAddMenuItem");

                $.writeln(this.requiredContext);

                return false;

      }

       

       

      /**

        "main program": construct an anonymous instance and run it,

        as long as we are not unit-testing this snippet.

      */

      if(typeof(SnpAddMenuItem_unitTest ) == "undefined") {

                new SnpAddMenuItem().run();

      }