0

I want to be able to run a google apps script as a "macro" with params.

For example, I navigate to script.google.com, that'll show me which scripts are available. I click one of them, then hit "Run" to run it. When I run it, I want to have the script prompt me for some input, and then it'll run some code to create a folder in Drive, some files, give permissions to those files, etc.

In terms of getting input from the person running the script, I don't care if they can pass it in somehow (like cmd line args) or if the code can just prompt the user for the input (console input is fine).

What's the best way to do this?

Rubén
  • 34,714
  • 9
  • 70
  • 166
Jack
  • 2,206
  • 3
  • 18
  • 25

1 Answers1

1

The Run command form the Google Apps Script editor can't open a user interface from stand alone scripts. You might use a Google Workspace Editor file (document, form, slide or spreadsheet) as a container of your script, then display a prompt, dialog or sidebar on the corresponding web application. For details see https://developers.google.com/apps-script/guides/dialogs

Also you might create your own web application. For details see https://developers.google.com/apps-script/guides/web

Also you might call your Apps Script function from other place by using Google Apps Script API. For an overview see https://developers.google.com/apps-script/api

Also you might use a CLI by using CLASP.

But maybe the simpler way is to create a function to set the values of the parameters and to call the parametrized function. In order to reduce the number of function on the IDE dropdown you set the parametrized functions as private functions (add a _ at the end of the function name)

Related

Rubén
  • 34,714
  • 9
  • 70
  • 166
  • I did the last, just have a function that calls the real function. Somebody running the script would then modify the outer function, eg, setting values of variables. Clumsy to be sure, but ok for our audience. – Jack Feb 22 '21 at 16:44