Tutorial

Getting Started with Macros

Macro Editor

User Interface

Menus and Toolbar

Editing Macros

Macro Debugging

How To

Using variables

Finding and modifying objects

Creating new page content

Asking for user input

Storing persistent data

Using binary data

Sorting objects

Macro menus

Bulleted and numbered lists

Sample Macros

Concepts

Expressions

Objects

Properties

Variables

Data Types

Arrays

Functions

Literals

Operators

Comments

Last updated on: September 02, 2024
Also available as a single HTML file

Onetastic Macro Documentation > How To > Macro menus

Macro menus

Each macro adds a button to the ribbon to run the macro. Optionally, macros can display a menu in the ribbon for more options. For example, Function macro displays the following menu:

Function macro menu

Macro menus can be static or dynamically generated based on user's usage patterns. For instance a macro like Search and Replace may display the recently used search and replace terms in the menu.

Setup function

Both static and dynamic menus are created by the Setup function. Setup function is a user defined function in a macro which will get called whenever Onetastic needs to get a macro's menu to be displayed in the ribbon. Below is a sample Setup function:

function Setup(byref $menu) MacroMenu_AddItem($menu, "arg1", "Menu Item 1", "Description for Menu Item 1") MacroMenu_AddItem($menu, "arg2", "Menu Item 2", "Description for Menu Item 2") MacroMenu_AddItem($menu, "arg3", "Menu Item 3", "Description for Menu Item 3")

Setup function always has a single parameter byref $menu. This parameter is an object of type MacroMenu. You can then use the MacroMenu_AddItem function to add menu items. A macro with this Setup function will have the following menu:

A macro menu

Each menu item is associated with an argument that will be passed to Main function when user clicks on that menu item. In this case if user clicks the first menu item, Main function for this macro will be called with the argument "arg1".

Performance Considerations

Setup function will get called every time Onetastic needs to refresh the menu for each macro. This can be after a macro execution, after a macro is edited, or after a new macro is downloaded. To avoid performance problems, Setup function should do minimal work and should not be running for a long time. Setup function for a macro will get aborted if it runs long and the menu for that macro will not be visible. Setup function also cannot access OneNote content or show dialog boxes.

Creating and Editing Setup Function

Macro editor makes it easy to create a setup function quickly via the following menu:

Create Macro Menu

This will create a sample Setup function which you can use to quickly edit. If a Setup function already exists, this will switch to it.

Debugging Menu Items

As macro menu items pass arguments to the main function, you may want to debug the execution of your macro with such arguments. The debug button in the Macro Editor toolbar has a split menu that makes it easy to pick the menu items and debug their execution:

Debugging Macro Menu

This menu will display each menu item and clicking on one of them will start the debugger with the associated argument passed to the Main function.

Reference

Statements

Hierarchy Objects

Page Objects

Other Objects

Functions

Array Functions

Color Functions

Data Store Functions

Date/Time Functions

Dialog Box Functions

Macro Execution Functions

Macro Menu Functions

Object Functions

Special Functions

String Functions

Window Functions