0
votes

I have a very simple bound script. The script works great, but if i share the sheet, editors have to trigger the script manually for the first time (in order to get auth dialog).

Is there a way i can trigger this dialog automatically? The sheet does not work properly without it.

I was thinking of setting a ridiculous "RUN THE SCRIPT!" text I would delete when the script is run for the first time, but that does not seem like an elegant solution.

1
Have you tried the "Open" event trigger? Google Documentation - Events There are two "Open" event triggers for Sheets, the simple, and installable. The simple trigger requires only that you create a function named onOpen(). So, when the sheet is opened, it will automatically run the onOpen() function. - Alan Wells

1 Answers

0
votes

After spending a lot of time on this problem, it seems that it is not possible to achieve this. Scripts that require authentication will silently fail (there is a way to let the script author know this, but not the user). Some actions do not require auth, and these will run if you are careful. I was toying with the idea to show something (menu item? alert?) to unauthenticated users, making them aware that the script is available and that it should be run.

But unfortunately the only way to determine the state according to the documentation AuthMode is not available to bound scripts:

scripts that are bound to a document, including add-ons in development, always run onOpen(e) in AuthMode.LIMITED

There must be a very good reason for Google not allowing such a basic functionality. I wish I would at least know why.