Skip to content

Instantly share code, notes, and snippets.

Avatar

Leo leoherzog

View GitHub Profile
@leoherzog
leoherzog / Code.gs
Last active Jul 5, 2022
Gather All Google Drive Files of a Certain Type and Change Owner
View Code.gs
const newOwner = 'blah@example.com';
const fileTypesToTransfer = ['application/vnd.google-apps.form']; // https://developers.google.com/drive/api/guides/mime-types
function changeOwnership() {
console.log('Gathering all files in Drive of type ' + fileTypesToTransfer.join(',') + '...');
let fileIterator = DriveApp.searchFiles(fileTypesToTransfer.map(x => 'mimeType = "' + x + '"').join(' or '));
let files = [];
while (fileIterator.hasNext()) {
@leoherzog
leoherzog / Code.gs
Created Mar 18, 2022
Find emails in your Google Directory for names in a Google Sheet
View Code.gs
/*
* This is a script to look through column x for names,
* search your directory for email addresses for that name,
* and print them into column y.
*
* To get started:
* 1. Open an existing Google Sheet or create a new one (https://sheets.new) and give it a name.
* 2. Click Extensions Apps Script and give that new Apps Script project a name (e.g. "Lookup Email from Name").
* 3. Paste all of this code into that project.
* 4. Specify if it has a header row on line 19 of the code (true or false), as well as the name and email column letters on lines 20 and 21.
@leoherzog
leoherzog / code.gs
Last active Feb 22, 2022
Google Drive Folder ID Finder
View code.gs
/**
* This script creates a simple web app where the visitor can select a Google Drive folder with the Google Picker and it will tell you the ID of the folder, since that's now hard to find in the Google Drive web app or Folder URL.
* To get started:
* 1. Go to script.google.com and log in as the user that you want to host this published web app.
* 2. Click "New Project".
* 3. Rename the project at the top from "Untitled project" to something else (ex. "Folder ID Finder")
* 4. Copy/paste this code over the default "myFunction" starter code that's currently there
* 5. Click the ➕ next to "Files" in the sidebar, add an "HTML" file, name it "index" (.html is added by Apps Script), and paste the `index.html` code below over the starter code in that file.
* 6. Click "Deploy ▼" → "New Deployment". In the "Select Type" ⚙️ gear, choose "Web App". Change "Execute as" to "User accessing the web app" and "Who has access" to "Anyone with a Google Account". Click "Deploy".
* You're done! The long "Web app" URL c
@leoherzog
leoherzog / code.gs
Created Aug 9, 2021
Google Shared Drive Viewers Automator
View code.gs
/**
* @OnlyCurrentDoc
* 1. Create a new Google Sheet (https://sheet.new) and remove all but one column
* 2. Add all of the email addresses in Column A that you'd like to have as viewers on the Shared Drive
* 3. Click Tools → Script Editor and copy/paste all of this code into the editor
* 4. Edit the Shared Drive ID on line 10 (https://drive.google.com/drive/folders/{Shared Drive ID})
* 5. Click "▷ Run" in the top toolbar, allow authorization, and you're done!
*/
const sharedDriveId = '0AAt_DfuXH73UUA9dVp';
@leoherzog
leoherzog / code.gs
Created Jun 3, 2021
Google Apps Script Philips Hue Sunrise-Sunset Color Temperature Changer
View code.gs
// updates the color temp of a hue group throughout the day, from blue in the morning to orange in the evening.
//
// copy these three to three files in a new apps script project (https://script.google.com/),
// make a new hue remote app id (https://developers.meethue.com/my-apps/),
// copy the app id and secret onto lines 54 and 55 of hue-oauth-stuff.gs,
// publish as a web app,
// go to the web app and authorize via oauth,
// run createBridgeUser() on the hue-oauth-stuff page,
// copy the new bridgeuser id onto line 15 of this page,
// change the groupname to the Hue group you want to change,
@leoherzog
leoherzog / code.gs
Last active May 20, 2021
Export Classic Google Sites Attachments to Google Drive Folder
View code.gs
// Go to script.google.com, click "New Project", copy and paste this code in, and click "▷ Run" in the toolbar
function run() {
let sites = SitesApp.getAllSites('example.com');
console.log('Total number of sites: ' + sites.length);
sites = sites.filter(site => {
try {
@leoherzog
leoherzog / code.gs
Last active Feb 23, 2021
Google Drive Folder Change Notifier
View code.gs
/**
* This script checks a Google Drive folder for any new files and/or folders added to it, and emails you if there are changes!
* To get started:
* 1. Go to script.google.com and log in as the user that you want to do the automated "checking".
* 2. Click "New Project".
* 3. Rename the project at the top from "Untitled project" to something else (ex. "Folder Change Notifier") and copy/paste this code over the default "myFunction" stuff that's currently there.
* 4. Add the folder IDs to the "foldersToCheck" array on line 16 below, in quotes, comma-separated. It should look something like:
* const foldersToCheck = ["1J5d673365fd944334be51d4163cd8294d", "1c5d63119b730c8224a218222e5faedcad"];
* 5. Add the email address that you want to notify for when there's changes on line 18 below. It should look something like:
* const emailToNotify = "name@gmail.com";
@leoherzog
leoherzog / code.gs
Created Sep 25, 2020
Google Drive Photocopier - Make lots of copies of a file in Drive
View code.gs
// (copy this into a new Apps Script project - https://script.google.com/)
// Hello!
//
// To make lots of copies of a thing in Google Drive,
// put the ID or URL of the Google Drive file here:
//
var fileToCopy = "https://jamboard.google.com/d/1jwdBuEjFtGvAjaRIsxXkR-nm-EgL2cES8UGOjREvdj0/viewer";
//
// Quotes are important! Example:
// var fileToCopy = "https://docs.google.com/document/d/1TIDOiUpPiWNqKqduKlbtm2O4jgFIAPrxuz_JFWzod9s/edit?usp=sharing";
@leoherzog
leoherzog / *setup.md
Created Sep 1, 2020
Windy.com Wunderground Temperature Scale
View *setup.md

Windy.com Wunderground Temperature Scale

  1. Go to windy.com
  2. Open the ☰ left sidebar and click Settings
  3. Scroll down and click 🎨 Customize color scale
  4. Select Temperature from the dropdown and scroll down to the small Import/Export section. Click [View Code].
  5. Paste the code from below into the text box on the page and click Save.

You're done!

@leoherzog
leoherzog / *README.md
Last active Dec 27, 2019
Google Drive TVDB Video Renamer
View *README.md

Google Drive TVDB Video Renamer

Google Apps Script code to go through a folder in Google Drive, recursively find all of the video files, and based off of the file names, rename them all to be consistent via information from The TVDB.

Setup

  1. Copy the two .gs files from this repo into a new Google Apps Script project
  2. Change the folder ID in the quotes in line 1 to the Google Driue folder ID that contains the video files (that can be found in the URL when opening the folder)
  3. Change the name of the show in the quotes on line 2 to be the name of the show
  4. Create a free account at the TVDB to obtain an API key. Get your API key information and copy it into line 84.
  5. Run the "run" function (and grant OAuth permissions if necessary)