How to Add Universal Template Menu Across All Google Documents

I need help making a template menu that shows up in every Google Doc I open, not just one specific document.

I built a Google Apps Script that formats documents with a specific template layout. The script itself works fine, but I can only get the custom menu to appear in the document where I originally created the script.

I want this menu to be available in ALL my Google Docs so I can quickly apply formatting whenever needed. All my documents get saved to the same folder anyway.

Is this even possible? I read somewhere that custom menus have to be tied to individual documents. If that’s true, what other options do I have?

function onOpen(e) {
  DocumentApp.getUi().createMenu('Format Templates')
      .addItem('Insert Client Report Layout', 'applyClientTemplate')
      .addToUi()
}

function applyClientTemplate() {
  var document = DocumentApp.getActiveDocument().getBody();
  
  var projectHeader = document.appendParagraph("Project Title");
  projectHeader.setHeading(DocumentApp.ParagraphHeading.TITLE);
  projectHeader.setAlignment(DocumentApp.HorizontalAlignment.CENTER);
  
  // more formatting code here...
  
  DocumentApp.getUi().alert('Client template has been applied successfully.');
}

Any suggestions would be really helpful. Thanks!

You’re right - container-bound scripts only work in the document they’re attached to. Here’s how to fix it: Create a standalone Google Apps Script at script.google.com instead of binding it to one document. Copy your code, but you’ll need to tweak the approach since onOpen won’t work across all docs. You can either make it a web app or run the formatting function manually from the Apps Script editor. If you want the menu everywhere, build a Google Docs add-on. It’s more work but gives you exactly what you want - that menu shows up in every Google Doc. Personally, I just keep a master template document and copy it for new projects. Way less automated but much easier to set up and maintain.

honestly, just bookmark your script file and run it from there. i do this constantly - open any doc, hit the bookmark, and it formats everything automatically. skip the complicated web apps or addons. copy your script to a standalone project at script.google.com, bookmark it, and you’re done. works everywhere and takes 2 minutes to set up.

I had the same problem and found a great workaround. Instead of putting the menu in every document, I built a Google Apps Script web app that works with any doc. I can pick my formatting options and they get applied to whatever document I have open. You’ll need to tweak your script to use DocumentApp.openById() for the document ID stuff. Takes about 15 minutes to set up once you’ve got your formatting functions ready. I thought about making a Chrome extension, but the web app’s cleaner and I can share it with my team.