Retrieving Icons of each mimeType on Google Drive using Google Apps Script

Gists

This is a sample script for retrieving icons of each mimeType on Google Drive using Google Apps Script.

Sample script

Sample list of mimeType is from this official document.

function getIcons() {
  const iconSize = 256; // Pixels
  const mimeTypes = [
    "application/vnd.google-apps.audio",
    "application/vnd.google-apps.document",
    "application/vnd.google-apps.drive-sdk",
    "application/vnd.google-apps.drawing",
    "application/vnd.google-apps.file",
    "application/vnd.google-apps.folder",
    "application/vnd.google-apps.form",
    "application/vnd.google-apps.fusiontable",
    "application/vnd.google-apps.jam",
    "application/vnd.google-apps.map",
    "application/vnd.google-apps.photo",
    "application/vnd.google-apps.presentation",
    "application/vnd.google-apps.script",
    "application/vnd.google-apps.shortcut",
    "application/vnd.google-apps.site",
    "application/vnd.google-apps.spreadsheet",
    "application/vnd.google-apps.unknown",
    "application/vnd.google-apps.video",
  ];
  const imageUrls = mimeTypes.map(
    (e) =>
      `https://drive-thirdparty.googleusercontent.com/${iconSize}/type/${e}`
  );
  const blobs = UrlFetchApp.fetchAll(imageUrls).map((r, i) =>
    r.getBlob().setName(`${mimeTypes[i].split("/")[1]}.png`)
  );
  const zip = Utilities.zip(blobs, "sampleIcons.zip");
  DriveApp.createFile(zip);
}
  • When this script is run, a ZIP file including icons is created to the root folder.

  • When iconSize is changed, it seems that the retrieved icon size can be changed. It seems that the smallest and the largest sizes are 16 and 256, respectively.

  • As a simple Javascript, you can also test this script here. https://jsfiddle.net/gut30kow/

 Share!