Google Apps Script snippets ᕦʕ •ᴥ•ʔᕤ

github stars contributorpw google-apps-script-snippets

What is it

This is a systematic view of Google Apps Script snippets sorted and grouped using Hugo. It also uses watchman and rsync and brename to build locally.

Why is this necessary

The main reason is to share knowledge. Often the documentation is insufficient to reveal the capabilities of a method or coding approach.

I wish I could have samples like these when I was learning to code.

What is a snippet

Snippet is a programming term for a small region of re-usable source code, machine code, or text. These simple and common-case snippets can be re-used within an Apps Script project.

How to use

Main approach

Just copy the files to your project.

Almost every snippet is provided with the main code file and a manifest. You need the manifest to know what additional libraries or services or scopes you may need to make the snippet work.

An example of a simple manifest

appsscript.json

{
  "timeZone": "America/New_York",
  "dependencies": {},
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8"
}

An example of a manifest with dependencies

Below is an example when using Advanced Docs Service. Usually, updating the manifest is enough for the program to request new permissions.

appsscript.json

{
  "timeZone": "Europe/Moscow",
  "dependencies": {
    "enabledAdvancedServices": [
      {
        "userSymbol": "Docs",
        "serviceId": "docs",
        "version": "v1"
      }
    ]
  },
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8"
}

How to see my manifest

You need to check-in the property Show "appsscript.json" manifest file in editor in your project settings.

How to merge manifests

When you take a snippet, you get two manifests: yours in the current project and the snippet manifest.

The snippet’s manifest should just extend your manifest. From the example above, you can see that we need to add only one object to the simple manifest.

Here it is

{
  "enabledAdvancedServices": [
    {
      "userSymbol": "Docs",
      "serviceId": "docs",
      "version": "v1"
    }
  ]
}

How can I help