Introduction
Every Google Workspace app—Sheets, Docs, Slides, and Forms—offers a built‑in onOpen trigger that lets developers add custom menus. While it’s easy to create a menu for a single app, many teams need the same functionality across all four tools, saving time and ensuring a consistent user experience. This article walks you through the process of building a universal custom menu with Google Apps Script, covering the shared script structure, the specific trigger code for each app, and the steps to deploy and test the solution. By the end, you’ll have a single, maintainable script that appears in the menu bar of any Workspace document, letting you centralise workflows and boost productivity.
Understanding the Apps Script environment across Workspace
Google Apps Script runs in a cloud‑based container that can be attached to a spreadsheet, document, presentation, or form. Although the underlying language (JavaScript) is identical, each host provides a distinct service object (SpreadsheetApp, DocumentApp, SlidesApp, FormApp) and a slightly different UI API. Recognising these nuances is essential because the addMenu method belongs to the Ui class, which each app exposes through getUi(). By abstracting the menu‑creation logic into a reusable function that accepts a Ui instance, you can write the core menu code once and reuse it in every container.
Designing a single script file for universal menus
Start with a master script that lives in a standalone project (File → New → Script). Inside, define the menu items and the functions they will call:
- Menu definition: an array of objects, each containing
nameandfunctionName. - addUniversalMenu(ui): loops through the array and calls
ui.createMenu('My Tools').addItem(...).addToUi(). - Shared actions: functions such as
showSidebar()orlogSelection()that perform the actual work; these are independent of the host app.
Because the script is standalone, you can link it to any document type via the “Add‑on” or “Project‑bound” approach, but the simplest method for internal teams is to copy the script ID into each file’s Apps Script editor and call the same onOpen wrapper.
Implementing the onOpen trigger for each app
Each Workspace app expects a function named onOpen that receives no arguments. Inside that function, obtain the appropriate Ui object and pass it to the universal helper:
- Sheets:
var ui = SpreadsheetApp.getUi(); - Docs:
var ui = DocumentApp.getUi(); - Slides:
var ui = SlidesApp.getUi(); - Forms:
var ui = FormApp.getUi();
Example:
function onOpen() { var ui = SpreadsheetApp.getUi(); addUniversalMenu(ui); }
Repeat the same pattern in the script files attached to Docs, Slides, and Forms, changing only the service used to fetch the UI. This minimal duplication keeps the menu logic centralised while satisfying each app’s requirement for a dedicated onOpen entry point.
Deploying and testing the menu in Sheets, Docs, Slides, and Forms
After saving the script, open a test file of each type and run onOpen manually once (via the script editor) to grant the necessary permissions. Once authorised, reload the document; the new “My Tools” menu should appear at the top. Verify that every menu item triggers the expected shared function, and use Logger.log() or the built‑in debugger to troubleshoot any app‑specific quirks. For a production rollout, consider publishing the script as an internal add‑on, which streamlines installation across the organisation and provides automatic updates whenever you modify the universal code.
Conclusion
Creating a universal custom menu for Google Sheets, Docs, Slides, and Forms is a matter of isolating the menu‑building logic from the host‑specific UI calls. By placing the core menu array and action functions in a single, standalone Apps Script project, and then writing lightweight onOpen wrappers that fetch the appropriate Ui object, you achieve a maintainable solution that scales across the entire Workspace suite. Deploying the script as an internal add‑on further simplifies distribution and future updates. With this approach, teams can enjoy a consistent set of tools no matter which Google app they are using, reducing duplication, cutting development time, and delivering a smoother user experience across the organisation.









