1

I've set up a script that essentially copies the contents from a 'template' folder within my google drive and moves the copied contents to a newly created folder elsewhere. The 'Template' folder will always hold 9 individual spreadsheets, each with their own unique bounded script.

The problem I'm having is that every time I copy the spreadsheets over, I have to reauthorise access for each of the 9 scripts before I can start using the functionality I've created.

I'd like to be able to assign or grant permission for the bound script to access the services it needs to during the process I use to copy the spreadsheet to a new location.

Here is an example of the code I use to copy over the spreadsheets. Is there anyway to access the script to assign permissions here?

function copyContents(template_folder, new_folder){
     var files = template_folder.getFiles();

     while (files.hasNext()) {
         var file = files.next();
         var file_name = file.getName()
         var copied_file = file.makeCopy(file_name,new_folder)
        // Assign permissions here...
    }
 }
Rubén
  • 34,714
  • 9
  • 70
  • 166

1 Answers1

1

It's not possible to grant authorization programmatically as this implies a security risk. The alternative is to publish your bounded scripts as add-ons so you authorize them once and you will be able to use them on any spreadsheet.

Bear in mind that you still should have to enable the addons on each of the documents you want to use them but this usually as simple as having a an onOpen menu that runs with ScriptApp.authMode.NONE

Note: I'm pretty sure that this was already asked and answered on this site.

Similar questions without answers with positive score

Rubén
  • 34,714
  • 9
  • 70
  • 166