Member-only story
One Code to Rule Them All: Deploying Editor Add-Ons Across Google Sheets, Docs, Slides, and Forms
Mastering Google Apps Script: Deploy Once, Run Everywhere 🚀

What’s The Issue? 🤔
Building add-ons with Google Apps Script is akin to owning a magic wand for distributing your application. And if you’re like me, you’ve probably created an army of internal add-ons for clients and personal use, especially those sweet editor add-ons. But here’s the catch: every time you deploy your add-on, you need to specify the script ID and the deployment version for each context (Docs, Sheets, Slides, and Forms). Keeping up with 4 different files isn’t just tedious; it’s like trying to juggle flaming swords while on a unicycle 🙃. But don’t worry, there’s a better way!
The Magic Of Dynamic Context 🧙♂️
See, running SpreadsheetApp.getUi()
from a Google Slides container can cause your app to crash, faster than a kid with an ice cream cone on a hot summer day. That's because you can't create menus, show sidebars, or modals in that context. But, wait for it... executing getUi()
from any of the four contexts returns the same Ui class. This means that, if we can get the context right, we can manipulate the UI in the same way across all contexts, thus…