Taking Advantage of Manifests by GAS Library

Gists

Introduction

By recent Google update (Google update at October 24, 2017), various new winds to GAS developers were blown. There is “Manifests” as one of the new winds. “Manifests” makes us manage the project using JSON. Especially, the special scopes which have to use OAuth2 process can be used by only setting them to the Manifests. I think that this is the largest modification. However, when scopes are added to a project using Manifests, users who use the project can use only added scopes. This means that when users create scripts in the project, if there are some scopes which is required to be added, such scopes cannot be automatically added. So the error of “Insufficient Permission” occurs.

Retrieving Size of Tables in Google Slides using Google Apps Script

Gists

This sample script is for retrieving the size (width and height) of a table in Google Slides using Google Apps Script.

There are no methods for directly retrieving the table size using SlidesApp yet. So I thought of a workaround using Slides API.

  • When the slide information is retrieved using Slides.Presentations.Pages.get() of Slides API, the information of tables is also included. In the information, the height and width of table are also included.
  • But the unit is EMU (English Metric Unit), and the height and width is separated by each cell. So it is required to sum each height and width while modifying the unit.

The modified script reflected this is as follows.

SlideApp for Google Slides

Gists

By recent Google updated, Class SlideApp is added to Google Slides. SlideApp will be bring a lot of applications. Here, I would like to introduce 2 samples.

1. Sidebar

function showSidebar() {
  var html = HtmlService
    .createHtmlOutput('Hello, world! <input type="button" value="Close" onclick="google.script.host.close()" />')
    .setTitle('My custom sidebar')
    .setWidth(300);
  SlidesApp.getUi().showSidebar(html);
}

2. Copy slides in existing Slide to a new Slide

This sample script create a new Slide with slides you want to copy.

GAS Library - RearrangeScripts

Overview

This is a GAS application for rearranging Google Apps Scripts (GAS) in a project which can be seen at the script editor.

Description

Have you ever thought about rearranging Google Apps Scripts in a project which can be seen at the script editor? I also have thought about it. Finally, I could find the workaround to do it. And recently, I have given this function to ggsrun which is a CLI tool. Furthermore, I thought that if there is a GUI application for rearranging scripts in a project, it may be useful for more users. So I created this. Today, I published this as a GUI tool using Google Apps Script. If this was useful for you, I’m glad.

GAS Library - ZipFolder

Overview

This is a library for zipping a folder using Google Apps Scripts.

Description

When users manually download a folder on Google Drive, users can download all files in the folder as a zip file using the web interface. There are zip tools in Class Utilities of Google Apps Script. However, the zip tools cannot create a zip file from a folder. And it cannot retrieve all files included any folders in a folder. So I created this. This library works like almost the same to the web interface using GAS.

GAS Library - ManifestsApp

Overview

This is a Manifests library for Google Apps Scripts.

Description

By recent update of Google, Manifests was added to Google Apps Script Project. At the moment I saw the detail, I thought that this Manifests will blow a new wind for a lot of GAS developers. So I created this.

This library makes users easily access Manifests using Google Apps Script. If this was useful for you, I’m glad.

GAS Library - ManifestsApp

GAS Library - ProjectApp

Overview

This is a GAS project library for Google Apps Script (GAS).

Description

There are Class SpreadsheetApp and Class DocumentApp for operating spreadsheet and document, respectively. But there is no Class for operating GAS project. If there is the Class ProjectApp, GAS project can be directly operated by GAS script. I thought that this will lead to new applications, and created ProjectApp.

On the other hand, as a CLI tool for operating GAS project, there has already been ggsrun.

Uploading Local Files to Google Drive without Authorization using HTML Form

Gists

This is a sample script for uploading local file to Google Drive without the authorization using HTML form. A selected file in your local PC using HTML form is uploaded to Google Drive and saved to Google Drive.

When you use this, at first, please deploy Web Apps. The script is doPost() of following scripts.

Script : Google Apps Script

function doPost(e) {
  var data = Utilities.base64Decode(e.parameters.data);
  var blob = Utilities.newBlob(data, e.parameters.mimetype, e.parameters.filename);
  DriveApp.createFile(blob);
  var output = HtmlService.createHtmlOutput("<b>Done!</b>");
  output.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
  return output;
  // return ContentService.createTextOutput("Done.") <--- Here, an error occurred.
}

Flow :

  • Retrieve data, filename and mimetype as e.parameters.data, e.parameters.filename and e.parameters.mimetype, respectively.
  • Decode the data using Utilities.base64Decode().
  • Create blob using Utilities.newBlob().
  • Create the file in the root folder of Google Drive.

Script : HTML

https://script.google.com/macros/s/#####/exec is the URL obtained when the Web Apps was deployed. Please replace it to your Web Apps URL. You can open this HTML for the browser of your local PC.

Create New Project with Original Manifests

It was found that you can also create new project with your original Manifests using ggsrun. By using this, for example, when you created new project, the project can have libraries, Advanced Google Services and so on at the initial stage. I think that this can be used as a template for Project.

$ ggsrun u -pn [Project name] -f appsscript.json

https://github.com/tanaikech/ggsrun/blob/master/help/README.md#ModifyManifests

Create New Project with Original Manifests

You can check this and download ggsrun at https://github.com/tanaikech/ggsrun.

Updated ggsrun to v133

ggsrun was updated to v.1.3.3

Awesome points of Manifests :

Awesome points of Manifests that I think are below.