Google app script desktop ide [duplicate]
Asked Answered
D

2

25

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?

Dextrality answered 26/2, 2018 at 6:58 Comment(0)
K
28

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");

Kerchief answered 15/6, 2019 at 9:38 Comment(4)
Seconding this. Use whatever ide you want and then use CLASP.Chlorinate
I had to run npm init before step 6 to avoid an error message about a missing package.json file.Unbridle
I want to apply this answer on Mac OS. Your initial, "on my PC..." make me wonder if this is possible. Does anyone know?Desecrate
@TonyM none of the steps in the answer is platform specific so it is possible on any platform with node.js support.Scevor
R
6

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!

Roxie answered 15/6, 2018 at 21:14 Comment(3)
You're saying that the Google libraries add autocomplete for the Google apps script language? And flag to the editor that many recent features of JavaScript are not available? That's the level of integration I believe OP is going forConsciousness
It definitely adds autocomplete support for the GAS libraries, although I haven’t gotten deep enough into iit to know whether it flags for unavailable JS features (I would presume it actually does not).Roxie
It doesn't flag unavailable JS features - you only find out about them by running the GAS script.Kerchief

© 2022 - 2024 — McMap. All rights reserved.