Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add item to existing menu in Google Apps Script

How do I add an item to an existing menu (in Google Docs) in Google Apps Script?

I can create a new menu and add an item to that:

DocumentApp.getUi().createMenu('MyMenu')
  .addItem('Insert My Thing', 'myFunction')
  .addToUi();

But it seems a bit ridiculous to add a whole menu for a single item that should really go under the existing "Insert" menu.

like image 901
Paul Draper Avatar asked Nov 25 '13 17:11

Paul Draper


People also ask

How does the custom menu work in Google Apps Script?

Each menu item in the custom menu is associated with a Google Apps Script function. When a menu item is selected, its corresponding function will be run. For example, if the menu item Setting A is selected, the corresponding function settingA () will be run and this function will display a toast notification.

How do I add a custom menu in Google Docs?

Apps Script can add new menus in Google Docs, Sheets, Slides, or Forms, with each menu item tied to a function in a script. (In Google Forms, custom menus are visible only to an editor who opens the form to modify it, not to a user who opens the form to respond.)

Can editor add-ons have menu items in Google Sheets?

Note: Editor add-ons can have menu items as well, but use special rules they are defined. You can also assign an Apps Script function to an image or drawing in Google Sheets, so long as the script is bound to the spreadsheet. The example below shows how to set this up.

Can a script create a menu in Google Forms?

(In Google Forms, custom menus are visible only to an editor who opens the form to modify it, not to a user who opens the form to respond.) A script can only create a menu if it is bound to the document, spreadsheet, or form.


1 Answers

Currently it is not possible. Even though the documentation says

A document, spreadsheet, or form can only contain one menu with a given name. If the same script or another script adds a menu with the same name, the new menu will replace the old.

when I tried the following code

DocumentApp.getUi().createMenu('Tools')
  .addItem('Tool_item', 'toolItem')
  .addToUi();

another Tools menu was created:

enter image description here

like image 174
Bartek Avatar answered Oct 06 '22 00:10

Bartek