MacGap.Menu

Properties description
menuItems list of current menu’s items
type type of menu

MacGap.Menu.getItem(identifier)

Get a reference to an existing MenuItem in the menu.

Arguments

Argument description
identifier Label (string) or the index (int) of the MenuItem

Example

This example grabs a MenuItem from the top bar called ‘File’.

if(MacGap.Menu.getItem('File')) {
    console.log('This menu bar has a File MenuItem');
} else {
    console.log('This menu bar does NOT have a File MenuItem');
}

MacGap.Menu.addSeparator()

Adds a line between MenuItems.

Example

Adds a separator between two different MenuItems.

var fileMenu = MacGap.Menu.getItem('File').submenu;
fileMenu.addItem({'Save'});
fileMenu.addSeparator();
fileMenu.addItem({'Quite'});

MacGap.Menu.addItem(properties, callback)

Add a new MenuItem to the menu. On click the callback will be invoked.

Arguments

Argument description
properties label (string) - the displayed text, index (int) - the position in the menu, keys (string) - key bindings to invoke the MenuItem
callback Function to be invoked when the menu item is clicked

Example

Add and bind a MenuItem to a callback. Consider that your javascript runs on multiple page loads, we should consider the following:

  • the MenuItem should only be added one time
  • the original callback bound to the MenuItem may be destroyed

// Your javascript code may run on each page load, so check if the menu item is already in the bar.
if (!MacGap.Menu.getItem('Tasks')) {
  // add the new menu item, the return value is the MenuItem object
  MacGap.Menu.addItem({ label: 'Tasks', keys: 'cmd+g', index: 1});

  // get a reference to the new item's Menu object to add new items to it
  var menu = MacGap.Menu.getItem('Tasks').submenu;

  // add a new item
  menu.addItem({
      label: "Testing"
  }, function () {
      // callback for when the menu item is clicked
  });
} else {
  // rebind the callbacks to the menu item if the page has changed
  var menu = MacGap.Menu.getItem('Tasks').submenu;
  menu.getItem('Testing').callback = function() {
    // callback for when the menu item is clicked
  };
}

MacGap.Menu.create()

TBD

Arguments

Argument description
title title (string) for the menu
type Optional or set to ‘statusbar’ for status bar menus