Communities for Google Apps Script

Gists

Consumer (personal) version of Google+ is closed on April 2, 2019. By this, Apps Script community of Google+ is also closed. This is one of important communities for discussing. So in this post, I would like to introduce the other communities related to Google Apps Script.

  1. As the next community of Apps Script community of Google+, Google Apps Script Community was launched.

  2. Stackoverflow: https://stackoverflow.com/questions/tagged/google-apps-script

Parsing Query Parameters from URL using Google Apps Script

Gists

This is a sample script for parsing query parameters from an URL using Google Apps Script. Also this can be used at Javascript. The process cost becomes a bit lower than that of the script using the regular expression.

Sample script

function parseQuery(url) {
  var query = url.split("?")[1];
  if (query) {
    return query.split("&")
    .reduce(function(o, e) {
      var temp = e.split("=");
      var key = temp[0].trim();
      var value = temp[1].trim();
      value = isNaN(value) ? value : Number(value);
      if (o[key]) {
        o[key].push(value);
      } else {
        o[key] = [value];
      }
      return o;
    }, {});
  }
  return null;
}

// Please run this function when you test this script.
function main() {
  var url = "https://sampleUrl.com/sample?key1=value1&key2=value2&key1=value3&key3=value4&key2=value5";
  var res = parseQuery(url);
  Logger.log(res);
}

Result

{
  "key1": [
    "value1",
    "value3"
  ],
  "key2": [
    "value2",
    "value5"
  ],
  "key3": [
    "value4"
  ]
}

Trend of google-apps-script Tag on Stackoverflow 2019

Gists

March 25, 2019 Published.

Kanshi Tanaike

Introduction

At Stackoverflow, a lot of people post the questions and answers to the questions every day. There are various tags in Stackoverflow. A lot of discussions are performed at each tag. Their discussions bring the important information and are much useful for a lot of people. As one of tags, there is “google-apps-script”. I sometimes discuss at the questions with that tag. When we see the discussions, we can notice that the discussions are changed and progressed by the time, because “Google Apps Script” which is the origin of the tag is updated. This report thinks this change as the trend of tag of “google-apps-script”. This trend includes the number of questions, questioners, answerers and tags adding to the tag of “google-apps-script”. The trend of tag of “google-apps-script” is deeply related to the progression of Google Apps Script and the various applications for Google Apps Script.

Modify Shading Color of Paragraph on Google Document using Google Apps Script

Gists

This is a script for modifying the shading color of paragraph on Google Document using Google Apps Script.

Recently, by releasing Google Docs API, the shading color got to be able to be modified using the script. Here, I would like to introduce a sample script for modifying the shading color of the paragraph on Google Document. At the current Document Service, the shading color cannot be modified yet. I think that this will be achieved in the future update. At that time, I think that a new property might be added to Enum Attribute.

Adding Title of vAxis to Embedded Chart on Spreadsheet using Google Apps Script

Gists

When a chart is created by using EmbeddedChartBuilder of Spreadsheet service, the title of vAxis which is put by setOption("vAxis", {title: "y axis"}) doesn’t work. It is considered that this is a bug. Because I have confirmed that this had worked fine. Ref But this specification had been changed. So I would like to introduce the method for adding the title of vAxis when a chart is created using Google Apps Script.

tarUnarchiver for Google Apps Script

Overview

This is a script for extracting files from a tar file using Google Apps Script. This script was created by native Google Apps Script.

The following 3 situations gave me the motivarion for creating this script.

  1. Although I had been looking for the script for extracting files from a tar file from before, I have still not been able to find it.
  2. Unfortunately, there are no methods for extracting the files from the tar file in Google Apps Script. But fortunately, from wiki of tar, I could retrieve the structure information of the tar data. And I can also study by creating this script.
  3. I found this thread at Stackoverflow. By this, I could understand that other users also want the script for extracting files from the tar file.

So I created this.

Sample Script for Executing with Synchronous Process using Node.js

Gists

This is a sample script for executing with the synchronous process using Node.js.

Sample script

function work(e) {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            console.log(e);
            resolve("ok" + e);
        }, 1000);
    });
}

async function main() {
    var ar = [1, 2, 3, 4, 5];
    for (var i = 0; i < ar.length; i++) {
        console.log('start' + ar[i]);
        await work(ar[i]).then((res) => console.log(res));
        console.log('end' + ar[i]);
    }
}

main(); // Run main().

Result

start1
1
ok1
end1
start2
2
ok2
end2
start3
3
ok3
end3
start4
4
ok4
end4
start5
5
ok5
end5

GAS Library - ProcessApp

Overview

This is a library for retrieving the process and information of Google Apps Script.

Methods

  1. getExecutionTimeOfTrigger() : This method retrieves the total execution time of all functions executed by the time-driven trigger at owner’s account. For example, you can know the total execution time of all functions executed by the time-driven trigger in 24 h.
  2. getDevUrl() : This method retrieves the endpoint of developer mode for Web Apps like https://script.google.com/macros/s/#####/dev.
  3. getRunningFunctions() : This method retrieves the functions which are running now.

You can check this at https://github.com/tanaikech/ProcessApp.

Creating One-time Writing Cells using Google Apps Script

Gists

This sample script is for creating one-time writing cells using Google Apps Script. At first, it supposes the following situation.

  1. A Spreadsheet is shared with users. The owner of Spreadsheet is you.
  2. After users put a value to a cell, you don’t want to make users edit the cell again.
    • Namely, you want to protect the cell.

This sample script achieves above situation.

Preparation

Before you use this script, please do the following flow.