AI-generated Key Takeaways
- 
          Custom menus are part of the user interface for a Google App and can only be interacted with by container-bound scripts. 
- 
          The provided example demonstrates how to create a custom menu with items, a separator, and a submenu using Apps Script. 
- 
          Key methods for creating a custom menu include addItemto add menu options,addSeparatorfor visual separation,addSubMenuto add nested menus, andaddToUito display the menu.
- 
          Each menu method returns the Menuobject for chaining except foraddToUi, which returnsvoid.
A custom menu in an instance of the user interface for a Google App. A script can only interact with the UI for the current instance of an open document or form, and only if the script is container-bound to the document or form. For more information, see the guide to menus.
// Add a custom menu to the active spreadsheet, including a separator and a // sub-menu. function onOpen(e) { SpreadsheetApp.getUi() .createMenu('My Menu') .addItem('My Menu Item', 'myFunction') .addSeparator() .addSubMenu( SpreadsheetApp.getUi() .createMenu('My Submenu') .addItem('One Submenu Item', 'mySecondFunction') .addItem('Another Submenu Item', 'myThirdFunction'), ) .addToUi(); }
Methods
| Method | Return type | Brief description | 
|---|---|---|
| add | Menu | Adds an item to the menu. | 
| add | Menu | Adds a visual separator to the menu. | 
| add | Menu | Adds a sub-menu to the menu. | 
| add | void | Inserts the menu into the instance of the editor's user interface. | 
Detailed documentation
addItem(caption, functionName) 
Adds an item to the menu. The label for a menu item should be in sentence case (only the first word capitalized).
Parameters
| Name | Type | Description | 
|---|---|---|
| caption | String | The label for the menu item, with only the first word capitalized. | 
| function | String | The name of the function to invoke when the user selects the item. You can
    use functions from included libraries, such as Library.libFunction1. | 
Return
addSubMenu(menu)  
addToUi()  
Inserts the menu into the instance of the editor's user interface.