Develop app scripts in a local IDE

Akshit Baunthiyal
4 min readJun 3, 2021

Writing scripts is a boon for Google Workspace guys. You can add functionality to drive files that did not exist by default. Sending emails on a schedule (I wrote an article on it previously — https://www.linkedin.com/pulse/sending-emails-schedule-google-apps-script-akshit-baunthiyal/), sharing calendars out, changing user licenses, etc. are just some of the things you can do.

But where do you write this code? We are provided with a ‘platform’ for it. Simply going to script.google.com should sort us out.

The good thing about this is that we can write code online in the editor Google provides. This has recently been updated to give it a more VS Code like look and functionality. We have autocompletion for advanced google services (https://developers.google.com/apps-script/guides/services/advanced). However, we can use IDEs on our computers to develop locally. This gives us the power to use features not provided by the online editor.

I decided to write something that narrates the process I followed to get started with it. Full disclosure — This article isn’t about why you would want to do that. Rather about how one can start developing locally. I use VS Code.

Clasp allows you to develop your Apps Script projects locally. That means you can take advantage of things that aren’t possible directly from the editor that Google provides. Things like source control. I am using Windows so things are going to be Windows oriented although the steps should be pretty much the same with other OS (Mac or Linux).

Here goes -

  • Install Node.js from https://nodejs.org. The process is pretty straightforward. From what I understand, we need Node only for npm which will in turn help us install clasp.
  • Install clasp using node — Open the terminal and run the command npm install -g @google/clasp. Granted that Node.js is installed and the npm executable is in your current or global path, this will install clasp globally simply meaning all projects on your local machine should be able to use clasp. You need to import the definitions for using autocomplete, but more on that later.
  • Enable Apps Script API in the account where you want your scripts to rest and work. Here’s the link to the URL — https://script.google.com/home/usersettings
  • Login to that account using clasp — clasp login (please don’t chastise me for using VS Code’s built in terminal)
  • (point added later) Create a folder (project folder) and change to that directory. All the clone/create/push/pull stuff can be done in folders. This will make sure one script does not create problems with another and you do not lose data.
  • Here’s where you have a choice. You can either -
  • Start with a brand new project. For that, you need to use the command clasp create — title <titleName>
  • Clone an existing project. For that, you need to use the command clasp clone <script ID>. The ID of the script can be fetched in the following way -
  • Open script.google.com and go to the project
  • Click on the ‘cog’ icon
  • Copy the script ID
  • Now that we have a copy of the code we want to work on, we should get started with enabling autocomplete.
  • Install Google Apps Script definitions — npm install -g @types/google-apps-script. We installed this globally so that all projects can import type definitions for Apps Script and use autocomplete.
  • Create a file called import.js and add this line to it — import ‘google-apps-script’
  • Create another file called .claspignore and add this line to it — import.js. The .claspignore file will direct clasp to ignore the import.js file when we are pushing our code to Google (script.google.com).
  • You can also install clasp locally. In that case, you will not have to import google-apps-script but then, you will have to install @types/google-apps-script for each Apps Script Project.
  • Clasp push will push changed files to the platform (script.google.com)
  • Clasp pull will pull changes from the platform (script.google.com)

Here are some resources that might help you -

  1. Clasp — https://developers.google.com/apps-script/guides/clasp (https://github.com/google/clasp)
  2. VS Code — https://code.visualstudio.com/
  3. Node.js — https://nodejs.org/
  4. Google Apps Script definitions — https://www.npmjs.com/package/@types/google-apps-script

--

--

Akshit Baunthiyal

I'm a Google Workspace admin who sometimes dabbles in code.