Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google app script desktop ide [duplicate]

Tags:

I like to use google sheets with app script, but the online script ide is a hassle(lags...etc) and does not have many of the conveniences of a desktop ide. Hopefully, Google will make a desktop ide at some point. Does anybody know of a less painful way of making Google app scripts? Are there any good ides that support remote update or publishing a Google script?

like image 849
prothan Avatar asked Feb 26 '18 06:02

prothan


2 Answers

I use Visual Studio Code to edit my Google Application Scripts projects on my PC.

However rather than copy and paste the code produced into the online Google script editor, I push it using 'clasp'. Here are the steps I did to set up my dev environment on my PC.

Setup dev environment

  1. Install clasp (https://developers.google.com/apps-script/guides/clasp)

  2. clasp login

    opens up a browser window where you choose your google account that clasp will authenticate itself as. You will also give clasp a number of permissions which allow it (amongst other things) to deploy google app scripts to your google account.

  3. Turn on 3rd party support in scripts : (https://script.google.com/home/usersettings) and set Google Application Script API to "On".

  4. clasp clone <script-id>

    clones your script project to the current directory. If you only have the default script (Code.gs) in your project this will clone Code.js and appsscript.json to your current directory. .gs scripts are renamed to .js when cloned. appsscript.json is the project manifest.

    To get the script project id, open the script editor, go to File->Project properties->Info and copy the 'Script ID' you find in there.

  5. Create a git repo in your current directory to track script project code revisions.

  6. npm i @types/google-apps-script

    installs the Google Application Script libraries which enable Visual Studio Code to autocomplete Google Application Script classes and methods. Do this in the same directory as you cloned your script project.

  7. Edit the script project in Visual Studio Code.

  8. clasp push

    pushes your script project to script.google.com to allow you to test your changes.

Logging debug info

What this setup doesn't give you is a way to use a debugger to debug your application script.

However you can log debug information to the 'My Executions' section of your scripts home page: https://script.google.com/home/executions

Note that this only works from script functions that you call from triggers/custom menus (https://developers.google.com/apps-script/guides/menus). It does not work for custom functions. So any logging you attempt from a google sheets custom function invoked from a google sheets formula will not end up in the My Execution logs.

For logging to be viewable in the 'My Executions' it must be logged using the console class (https://developers.google.com/apps-script/reference/base/console). For example:

console.log("Some useful debug info");

like image 180
Joman68 Avatar answered Sep 29 '22 15:09

Joman68


I have had a similar experience and recently started using Visual Studio Code for its Intellisense, autocomplete, editor colors, and other useful features. Install the Google libraries and Nodejs, and you'll have an extremely robust environment in which to write .gs code which you can then copy/paste into your online Google script editor.

Simply change the editor language to JavaScript, and the IDE will recognize the code.

enter image description here

Good luck, I hope this helps!

like image 25
Paul Karkoska Avatar answered Sep 29 '22 15:09

Paul Karkoska