0

I use a script to generate about 20 files each day from a template. That template has some functions in a google script. And for all those files I run one of the functions (pZero function below) to create an onEdit trigger which will call onMyEdit() function whenever someone edits the file. I do it on Mac or Windows in the Chrome browser. The idea is to allow other editors of that file to make use of functionality of onEdit events, when they edit the spreadsheet in Google Sheets App for Android. Everything works fine, but the problem is that for every file I need to manually run that function and system asks for authoriziation of that script. This is very time consuming and annoying (I just counted that 7 mouse clicks needed to grant access). Is there any way to automate this process or to disable authorization warnings somehow or add the function to relied functions somehow. I even tried https://myaccount.google.com/lesssecureapps to turn off authorization request, but that didn't help.

Edit: This post is related, however it's problem is regularly changing code in a single file, and that solution won't help me. My code isn't changing, I just make many copies of sheets which already have the same script in them.

function onOpen(){  
  // Adding my function in custome menu
  var menuEntries1 = [ {name: "p0 functionality", functionName: "pZero"}];
  SpreadsheetApp.getActiveSpreadsheet().addMenu("Authorize",menuEntries1);
}

function pZero(){
  // Adding trigger, which calls my custom onMyEdit() function on onEdit() event
  if(ScriptApp.getProjectTriggers().length==0)
    var trigger = ScriptApp.newTrigger("onMyEdit").forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet()).onEdit().create();
}

function onMyEdit(){
// Some code to copy from the current file to another file not owned by the user of this file.
...
}
snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
eRic
  • 15
  • 8
  • Use techniques from [here](https://stackoverflow.com/q/49317412/9337071) to reduce the auth scope, which will reduce the needed clicks. If you can avoid needing an installed trigger for your on edit functionality, even better. If you need "3rd party" sheets and services that require authorization, then publish an add-on and use that, so the people using the copies can do authorization steps (and as a verified app, the click count will be lower). – tehhowch Mar 17 '18 at 12:06
  • @tehhowch, the problem is that the onMyEdit() function needs to copy some data from the current file to another (fixed for all files and all days) spreadsheet, which it accesses via SpreadsheetApp.openById() function. – eRic Mar 17 '18 at 13:37
  • Then you'll need to make your script into an add-on, and install the add-on into the template. Because each copy of the template workbook uses a new script project, you have to keep authorizing it, and there is no way Google will just let a user run a script instance that they have not specifically authorized. – tehhowch Mar 17 '18 at 14:52

0 Answers0