The [menuRef] command.

Introduction

The menuRef command lets you create and manipulate menus in Alpha. The menu items can be manipulated using the new [menuItem] command.

Synopsis

The formal syntax of the [menuRef] command is:
menuRef subcommand ?options?
The possible subcommands are described below. Depending on the subcommand, various options can be additionally specified.

The [cancel] subcommand

This subcommand cancels a menu tracking session. The syntax is:
    menuRef cancel
It dismisses the currently opened menus and ends all menu tracking. If no menu was opened, the command returns silently.

The [clear] subcommand

This subcommand removes all the items from a menu. The syntax is:
    menuRef clear token
To remove only one item from a menu list, use the [menuItem remove] command.

The [count] subcommand

This subcommand returns the number of menu items in a menu. The syntax is:
    menuRef count token

The [create] subcommand

This subcommand creates a new menu. The complete syntax is:
    menuRef create ?options?
The command returns a token used in the other subcommands (as well as with the [menuItem] command) to uniquely identify the menu.
The available options are described in the Menu options section below.

The [delete] subcommand

This subcommand lets you delete a menu. The syntax is:
    menuRef delete token
After deletion, the token associated with this menu is not valid anymore and is removed from the list returned by the [menuRef list] command.

The [insert] subcommand

This subcommand lets you insert a menu in the menu bar. The syntax is:
    menuRef insert token ?-before token?
The -before option lets you specify the token of another menu before which the menu must be inserted in the menu bar. If unspecified, the menu is appended at the right of the menu bar (yet before the Help menu).

The [items] subcommand

This subcommand returns a list of all the items currently present in the menu, in the index order. The syntax is:
    menuRef items token
This command should not be confused with the [menuRef list] command which returns the current list of menus.

The [list] subcommand

This subcommand returns a list of the tokens corresponding to the currently existing menus. Each time a new menu is created, its token is appended at the end of the list, so this list is ordered from the oldest to the newest menu. The syntax is:
    menuRef list ?-name str?
Not all menus have a name: a name can be declared with the -name option in the [menuRef create] or [menuRef set] commands. The -name option of the [menuRef list] command can then be specified in order to find the corresponding menu token.

The [parent] subcommand

This subcommand returns the token of the menu's supermenu. The syntax is:
    menuRef parent token
It concerns submenus which have been inserted in some menu. If the menu is inserted directly in the menu bar, the command returns "menubar". If the menu is not inserted in any menu, the command raises an error.

The [remove] subcommand

This subcommand lets you remove a menu from the menu bar. The syntax is:
    menuRef remove token
The menu is removed but not deleted: its token remains valid.

The [set] subcommand

This subcommand lets you get or set some properties of a menu. The syntax can take two forms:
    menuRef set token option
    menuRef set token option value ?option value...?
In the first form the command returns the current value of the specified option. In the second form, it lets you set the value of one or several options.
The available options are described in the Menu options section below.

Menu options


Here is the description of the various options which can be passed to the [menuRef create] or the [menuRef set] commands:

Built-in menus

There are several built-in menus provided by Alpha. They are also identified by a token. Currently, the following menus are available:
TokenDescription
applicationthe Alpha application menu
dockthe menu containing custom items in the dock tile
contextualthe contextual menu triggered by a control-click
helpthe Help menu
servicesthe Services submenu

These menus cannot be deleted or removed using the [menuRef delete] and [menuRef remove] commands but their contents can be modified at will. The other commands work as expected, using the built-in token. For instance:
    menuRef count help

Examples

See a series of sample instructions in the [menuItem] command's documentation.

Last updated 2019-10-17 13:29:39