GAS-Terminal: Environment for smart execution of Google Apps Script

Running GAS is a pain.

Do you like Google Apps Script(GAS)? Me too! ๐Ÿ‘
I’ve written a lot of GASs to run system processes and maintain data. Most of them are run by various triggers automatically, but sometimes I need to run some scripts by hand. Then I’ll be reminded that “Running GAS is a pain!” Why? Because there is no smart way to run it and check the results.๐Ÿ˜“

How do you always execute it?

1. Script Editor
image
The Script Editor

This may be the most familiar method. You write some code, and click the Run button. That’s all. But it’s a pain to open the Script Editor every time, and you should change the code when you want to change the function’s parameter.

2. Buttons on the spreadsheet
Place buttons

Another way is to place buttons on your spreadsheet and associate your functions with those buttons. This article explains how to do it. This method is a little easier than opening the Script Editor to execute functions. However, as the number of functions increases, the number of buttons also increases, and it tends to get harder to organize. Also, there is still the problem of not being able to change function parameters. Moreover, if you want to know the result of the script execution, you still have to open the Script Editor, unless you have implemented output to a sheet.

Here comes GAS-Terminal !

So I created a tool to make it easier to manage and run GASs. Its name is GAS-Terminal (The name Terminal is because you can switch between various commands (i.e. functions) as if you were in Terminal.) This tool is implemented in Google Sheets, which allows you to execute functions in scripts associated with this sheet.

If you want to know how to use it, please check the GitHub repository !

The following is a running example.

a running example

How is this achieved?

There are some minor points, such as reading the command definition sheet and handling when switching commands, but I simply use the eval function to execute the command.

Here’s the execution logic.

      // Clears the log.
      TerminalSheet.instance.clearLog();

      // Sets the TerminalSheet as logger.
      LogUtils.logger = TerminalSheet.instance;

      // Gets the command definition.
      let commandDef:CommandDefinition = CommandsSheet.instance.findCommand(commandName);

      // Makes the parameter string.
      let params:string[] = TerminalSheet.instance.getParams();
      let paramsStr:string = "";
      if( params.length > 0 ){
          paramsStr = '"' + params.join('","') + '"';
      }

      // Make the function call string.
      let callStr:string = commandDef.funcName + "(" + paramsStr + ")";

      // Executes
      eval(callStr);

Conclusion

I use this tool to run 13 commands in order to maintain my system. How do you always execute GASs? I hope this tool will be useful to you.

I will continue to improve this tool. The next target for now is to incorporate support for longrunning.
If you have any good ideas, please let me know! ๐Ÿ˜ƒ

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website with WordPress.com
Get started
%d bloggers like this: