0
votes

I have a script that runs on a Google Sheets that is fed by a Forms entry. Basically, when I fill out a form, it creates an entry on the sheet. From that entry, a new document is created by my script that "prettifies" the fields on the sheet for distribution.

This sheet is located on a Team Drive, but in order to have the resulting document created in my drive, I had to place the unbounded script in my drive and reference the sheet. If I have it bounded to the sheet, it will always put the newly created document in the Team Drive -- which I don't want.

When it was bounded to the sheet, I had a trigger that would automatically create the document when the form was submitted. Now that the script is on my drive, triggering on submission is not an option. The only options I have are time based or calendar based, and neither of these really work -- unless I only want to get the document once a month or every single minute.

So now, the only way I know to execute the script is to do it manually every time, which is a major hassle and requires multiple steps no matter how you go about it.

Is there a way to trigger this script on command without having to open the Script editor, click the script I want, and then click run?

Why are there no keyboard shortcuts in Apps? I know about Ctrl+R -- but this only works if you already have the script you want highlighted in the top action bar. If I type Ctrl+R without it already highlighted, nothing happens. Nothing happens with Alt+R or Alt anything, really. I have tried simply tabbing 187 times to get to where I need, but the tab never seems to focus "in" the script menu area. It just bounces around the address bar, the shortcuts bar, etc.

NOTE: I do not want to make major changes to THIS script. It took forever to get this working right and I don't want to jack it up. I just want to be able to trigger it without having to go through 18 steps to do so.

1
When posting a question about code, please include a Minimal, Complete and Verifiable example. If you're making a copy of a template to create the document, check this out. - CalamitousCode
Also, this question might help you or this documentation about custom menus. - CalamitousCode
I feel your script probably only needed an extra step or so to create the file in your Drive and not the Team Drive. But, you showed no code here to illustrate how you were creating the file, so none of us can be sure. - tehhowch
I'd guess that you could use the Drive API to move the 'resulting document' to your drive. But I'd have to be able to view your code. - Cooper
Unfortunately, I have been unable to use any of the APIs due to our security restrictions. I did figure out a workaround -- I have a time-based trigger that runs every minute. If there is a new entry on the form's sheet, my script will do its thing and, when done, it will then make an entry in a cell in an unused column on the form sheet. My script then knows not to re-copy that same line again. - Paige OWENS-SC

1 Answers

1
votes

There is no way to execute a standalone script project's function with a keyboard shortcut from within the Apps Script Editor. If your script was bound, you would have the option of keyboard shortcuts from the container Google Sheets file (as a ), but macros have some restrictions.

However, you are not without options. Two of them:

  • Publish the script project as a webapp and use a page visit as the trigger.
    Open the page / click a bookmark -> execute the function via your doGet().
  • Convert your script to a 'polling' style that processes any number of form responses, and use a time-based trigger (e.g. hourly, daily) to automate the whole process.
    (Include a "did I process this response yet" flag to prevent reprocessing a response)

There are more elaborate configurations (e.g. Apps Script API + local cron job) but those are unlikely to be simpler than the above two options.


As I mentioned in my comment, you more than likely just needed an extra step for the original bound script to create the file in your Google Drive and not the host Team Drive. If you're interested in that avenue, you'll want to ask the appropriate (read: new) question.