Skip to content

Instantly share code, notes, and snippets.

@tanaikech
Created August 13, 2022 07:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanaikech/1c0bd1e88b67f19b77d79c9f631b001d to your computer and use it in GitHub Desktop.
Save tanaikech/1c0bd1e88b67f19b77d79c9f631b001d to your computer and use it in GitHub Desktop.
Retrieving Icons of each mimeType on Google Drive using Google Apps Script

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

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment