Google Scripts lets you create custom menus. For example:
function makeMenu(){
var ui = SpreadsheetApp.getUi();
ui.createMenu("Scripts")
.addItem("My Script","myScript")
.addToUi();
This works great if you have only ONE file you want to script.
Let's say, however, you have 50 files that you want to all have the same menu running the same functions.
You can easily update the functions themselves by putting them in a library and having those 50 files reference the library version HEAD:
function myScript(){
MyLibrary.myScript();
}
Now, if you want to update the myScript() function, you simply update it in your library, and the changes propogate.
However, I have two problems:
- The only way I can see to add a NEW menu function to all 50 files is to manually go into each file and add:
function myNewScript(){
MyLibrary.myNewScript();
}
Is there any way to update them all at once?
NOTE: While you could "library out" the "makeMenu" function, and the individual scripts would then have the new menu item, they will error out when the menu function is used, as the menu function will only call the function if it exists within the file itself (as opposed to the library).
- The only way I can see to use versioning with the library (so users can have a stable version while the developer works on the HEAD version) is, again, to manually go through all 50 files and update the library version.
Is there any way to use versioning without having to go into each file and manually update the library version it uses?
I did find this close-but-not-quite answer about dynamically updating menus; however, as far as I can tell, it will only work within a single script, and does not apply to libraries (see my NOTE for #1 above): Update app script executable functions menu as new functions are added