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 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.

Examples

An implementation of the example menubar script

Discussion

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

display and behavior [int]

Optional

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 application menu will appear to the left of the other menus.

Attributes

Common Box Attributes

annotation [symbol]

Sets the text that will be displayed in the Clue window when the user moves the mouse over the object.

background [int] (default: 0)

Adds or removes the object from the patcher's background layer. background 1 adds the object to the background layer, background 0 removes it. Objects in the background layer are shown behind all objects in the default foreground layer.

color [4 floats]

Sets the color for the object box outline.

fontface [int]

Sets the type style used by the object. The options are:

plain
bold
italic
bold italic

Possible values:

0 = 'regular'
1 = 'bold'
2 = 'italic'
3 = 'bold italic'

fontname [symbol]

Sets the object's font.

fontsize [float]

Sets the object's font size (in points).

Possible values:

'8'
'9'
'10'
'11'
'12'
'13'
'14'
'16'
'18'
'20'
'24'
'30'
'36'
'48'
'64'
'72'

hidden [int] (default: 0)

Toggles whether an object is hidden when the patcher is locked.

hint [symbol]

Sets the text that will be displayed in as a pop-up hint when the user moves the mouse over the object in a locked patcher.

ignoreclick [int] (default: 0)

Toggles whether an object ignores mouse clicks in a locked patcher.

patching_rect [4 floats] (default: 0. 0. 100. 0.)

Sets the position and size of the object in the patcher window.

position [2 floats]

g/s(set)

Sets the object's x and y position in both patching and presentation modes (if the object belongs to its patcher's presentation), leaving its size unchanged.

presentation [int] (default: 0)

Sets whether an object belongs to the patcher's presentation.

presentation_rect [4 floats] (default: 0. 0. 0. 0.)

Sets the x and y position and width and height of the object in the patcher's presentation, leaving its patching position unchanged.

rect [4 floats]

g/s(set)

Sets the x and y position and width and height of the object in both patching and presentation modes (if the object belongs to its patcher's presentation).

size [2 floats]

g/s(set)

Sets the object's width and height in both patching and presentation modes (if the object belongs to its patcher's presentation), leaving its position unchanged.

textcolor [float]

Sets the color for the object's text in RGBA format.

textjustification [int]

Text Justification

Possible values:

0 = 'left'
1 = 'center'
2 = 'right'

varname [symbol]

Sets the patcher's scripting name, which can be used to address the object by name in pattr, scripting messages to thispatcher, and the js object.

Messages

int

Arguments

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

Arguments

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 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

Arguments

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

Arguments

text of first menu item [list]
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 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

Arguments

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

Arguments

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

Arguments

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

Arguments

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

Arguments

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

Arguments

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).

Arguments

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

Arguments

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

Arguments

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

Arguments

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.

See Also

Name Description
Sharing Max Patchers Sharing Max Patchers
umenu Pop-up menu