A newer version of Max is available. Click here to access the latest version of this document.

menubar

Put up a custom menu bar

Description

The menubar object provides control over the Macintosh menu bar. It allows your patch to put up its own menus, and add items to standard File and Edit menus. When a menu item is chosen, the item number is sent out the outlet corresponding to the menu containing the item. You configure the menubar by writing a script in a text editor window available by double-clicking on the object in a locked patcher.
When you close the script window and confirm saving the changes, the script file is interpreted. If there are no errors, the customized menu bar will be ready for use when menubar receives a nonzero number in its inlet.
Each message should be preceded by #X and end with a semicolon (; ).
Here is an example menubar script:
#X about About Note Algorithms…;
#X closeitem;
#X menutitle 5 Algorithm;
#X item 5 1 Transpose;
#X item 5 2 Invert;
#X item 5 3 Randomize;
#X end;


Note that we suggest capitalizing each letter in a menu item to maintain a consistent style with other items in the menu.

Arguments

Name Type Opt Description
display and behavior int opt The argument sets the number of menus in the object's menu bar. If present, it must be at least 5 (one additional menu). The four default menus, which are always present, are File, Edit, Windows., and Help. On Macintosh, the Standard System Menu with the Apple icon and the Max/MSP application menu will appear to the left of the other menus.

Messages

int show-menus-flag (0 or non-zero) [int]
A non-zero number displays the menubar object's menus, 0 restores the previous contents of the menu bar (either the Max menus or the menus of another menubar object).
about text of first menu item [list]
This is a script message (see above) used to modify standard menus, and is the first item to appear in a script. It takes the following arguments:
• Text of the first menu item (i.e. About My Program…).

On the Macintosh the About item appears as the first item in the application menu (Max/MSP menu). On Windows, it appears as the first item in the Help menu. The message apple may be used optionally for compatibility with older Macintosh versions of Max.
append menu number item number text [list]
This is a script message (see above) used to append new menu items. It takes the following arguments:
• Menu number
• Item number
• Text of item
• metacharacters (Optional.)

The append message appends an item to an additional menu previously defined with a menutitle message.
You can alter the appearance of a menu item by including metacharacters in the item text (see the item listing below for more information).
apple text of first menu item [list]
(Macintosh only) This is a script message (see above) used to modify standard menus, and, when used, is the first item to appear in a script. It takes the following arguments:
• Text of the first menu item (i.e. About My Program…).

On the Macintosh the About item appears as the first item in the application menu (Max/MSP menu). On Windows, it appears as the first item in the Help menu. This message may be used optionally for compatibility with older Macintosh versions of Max.
(mouse) Double-clicking on the menubar object in a locked patcher will open a text editor window where you can insert a script to configure the menubar's appearance and behavior.
checkitem checkitem [list]
Followed by a menu number, an item number, and a code 0 or 1, checkitem puts a check before the specified item if the code is 1, otherwise it removes the check.
closeitem This is a script message (see above) used to modify standard menus. It causes a Close item to appear in the File menu, for closing the active window.
edit item number text [list]
This is a script message (see above) used to modify standard menus. It takes the following arguments:
• Item number to output
• Text of item to add to edit menu

The edit message inserts items into the standard Edit menu after the Clear item and before the Overdrive and Resume items (which are moved into the Edit menu when menubar is activated). A blank line separates the custom inserted items from the default items. Each item has a number associated with it which is sent out the third outlet of menubar when the item is chosen. The order in which your additional items appear in the Edit menu is determined by their order in the script, not by the (arbitrary) number associated with each item.
enableitem menu-number item-number and enable/disable-flag (0 or 1) [list]
Followed by a menu number, an item number, and a code 0 or 1, enableitem enables the specified item if the code is 1, otherwise it disables (and grays out) the item.
end This is a script message (see above) used to complete a script definition. The builds the menus and reports any errors encountered.
file item number text [list]
This is a script message (see above) used to modify standard menus. It takes the following arguments:
• Item number to output
• Text of item to add to file menu

The file message inserts items at the top of the standard File menu (before the Midi Setup... menu item). Each item has a number associated with it which is sent out the when the item is chosen. The order in which your additional items appear in the File menu is determined by their order in the script, not by the (arbitrary) number associated with each item.
item menu number item number text [list]
This is a script message (see above) used to create new menus and menu items. It takes the following arguments:
• Menu number
• Item number
• Text of item
• metacharacters (Optional.)

The item message adds an item to an additional menu previously defined with a menutitle message. The order in which your items appear in the menu is determined by their order in the script, not by the (arbitrary) number associated with each item. The item number argument only specifies the number which is sent out the menubar object’s outlet when the user chooses this item. It’s a good idea to start your item numbers at 1 and list the items in the order you want them to appear in a menu.
You can alter the appearance of a menu item by including metacharacters in the item text. For more on metacharacters, consult the Apple QuickTime Developer documentation found at:
developer.apple.com
A few of the recognized meta-characters are:
/ : followed by a character, assigns that character as a Command-key equivalent
< : followed by B, I, O, S, or U, specifies a font style (such as O for outline)
! : followed by a character, marks the menu item with that character
(: disables the menu item

Thus, these special characters cannot appear as part of the actual item text. For example, the text On/Off will appear as Onff_O, not as On/Off.
markitem menu-number item-number and ASCII-code [list]
(Macintosh only) Followed by a menu number, an item number, and an ASCII character code, markitem places the character next to the specified item. Common mark character ASCII codes are 18 for the check mark and 19 for the diamond mark. You may also wish to use the em dash (209) or bullet (165).
menutitle item number name of menu [list]
This is a script message (see above) used to create new menus and menu items. It takes the following arguments:
• Menu number (must be at least 5 and must not exceed the number of outlets specified in the argument to the menubar object.
• Name of menu

The menutitle message adds a new menu before the Window menu. The first additional menu is number 5. The menu number determines both the order of the additional menu in the menu bar and the outlet it uses when the user chooses its items. A menutitle message must appear in the script before any item messages that refer to its menu number.
newitem menu item number [int]
This is a script message (see above) used to modify standard menus. It takes the following arguments:
• Item number to output.

The newitem message followed by a non-zero number directs Max to send the specified number out the menubar object’s File menu outlet when the user chooses the New command from the File menu, instead of opening a new patcher window. The message newitem 0 (or the absence of any newitem message) causes the New command to behave normally.
open menu item number [int]
This is a script message (see above) used to modify standard menus. It takes the following arguments:
• Item number to output.

The open message followed by a non-zero number directs Max to send the specified number out the menubar object’s File menu outlet when the user chooses the Open... command from the File menu, instead of displaying the Open Document dialog box. The message open 0 (or the absence of any open message) causes the Open... command to behave normally.
saveas menu item number [int]
This is a script message (see above) used to modify standard menus. It takes the following arguments:
• Item number to output.

The saveas message followed by a non-zero number directs Max to send the specified number out the menubar object’s File menu outlet when the user chooses Save or Save As... from the File menu, instead of performing the standard Save actions. The number sent out the outlet when Save is chosen will be 1 less than the number sent when Save As... is chosen. The message saveas 0 (or the absence of any saveas message) causes the Save and Save As... commands to behave normally.

Information for box attributes common to all objects

Examples

An implementation of the example menubar script

See Also

Name Description
umenu Pop-up menu, to display and send commands