Skip to content

Instantly share code, notes, and snippets.

View mogsdad's full-sized avatar

David Bingham mogsdad

View GitHub Profile

Google Apps Script Gmail Utilities

##sendAndLabel(recipient, subject, body, options, label)##

An alternative to GmailApp.sendEmail(), which applies a label to the message thread in the sender's account.

Sends an email message with optional arguments. The email can contain plain text or an HTML body. The size of the email

@mogsdad
mogsdad / Google Apps Script Survey Workflow.md
Last active August 1, 2022 07:48
Google Apps Script workflow for an email survey. Written in response to StackOverflow question 18668828. http://stackoverflow.com/a/18669532/1677912

Google Apps Script Survey Workflow

The components involved in this workflow are:

  • A script to generate and send an email with an HTML form.
  • An html template for that email, which allows us to customize the email for each recipient.
  • A doPost() function to handle responses. The script must be [deployed as a Web App][1].
  • A spreadsheet to collect responses. The script will be contained in the spreadsheet, and extends the spreadsheet UI with a menu for sending a copy of the survey. (It could be adapted for standalone use, without the UI component.)

Here is an example of such a workflow, conducting a Commuting Survey. Recipients will receive a survey email like this:

SheetConverter library (formerly "Spreadsheet to HTML")

This is the source repository for the SheetConverter Google Apps Script library.

Libary documentation is available here.

Caveats

This script is incomplete, ignoring some types of formatting. (Feel free to fork and enhance it, if you wish! Broadly applicable enhancements can be merged and the library updated) There are also some known issues:

Calendar Copier

This Google Apps Script runs in a spreadsheet, where it prompts the user for the identity of two calendars, and a range of dates, then copies the corresponding events from one calendar to the other.

Caveats

This script is incomplete, ignoring a number of event attributes. (Feel free to enhance it, if you wish!) There are also some known issues:

  • All Day Events aren't really all day events. The createAllDayEvent() method should take care of this, but doesn't. Google Bug.
  • Recurrence isn't supported. (You can't find out the recurrence of existing events, so cannot recreate it.)
@mogsdad
mogsdad / GCalUtils.md
Last active May 10, 2021 17:39
Collection of Google Calendar related utility functions for Google Apps Script.

Google Calendar Utilities

getEventsWithGuest

Gets all events that occur within a given time range, and that include the specified guest email in the guest list.

###Parameters:###

@mogsdad
mogsdad / digest.js
Last active October 29, 2021 03:28
This Google Apps Script function returns a string representing the 16-byte MD5 digest of a given message. It was originally written as an answer to StackOverflow question http://stackoverflow.com/questions/16216868/get-back-a-string-representation-from-computedigestalgorithm-value-byte. It's been refactored to support adaptation to other digest …
/**
* Return string representation of MD5 digest of the given message.
*
* @param {String} message Message to be encoded.
*
* @return {String} 16-byte digest value
*/
function signMd5(message){
return digest(Utilities.DigestAlgorithm.MD5, message);
}
/**
* Move all values from source range to destination range. Upon
* completion, source range will be cleared. Source values will
* be moved into a destination range starting at the "top left"
* of the destination range, using the dimensions of the source
* range. This is a blind copy, with no overwrite test.
*
* @param {Range} source Range Object to take values from.
* @param {Range} destination Range Object to receive values.
*
@mogsdad
mogsdad / ForwardHuntGroup.js
Created April 13, 2013 05:18
This script was written as the answer to a StackOverflow question about forwarding emails to a rotating list of people. See http://stackoverflow.com/a/15984468/1677912.
/**
* Retrieves a given user label by name and forwards unread messages
* associated with that that label to a member of the Hunt Group.
*/
function huntGroupForward() {
// get the label for given name
var labelName = "elephant"
var label = GmailApp.getUserLabelByName(labelName);
if (label == null) throw new Error("No messages for label "+labelName);
// get count of all threads in the given label
@mogsdad
mogsdad / getContiguousRange.js
Created March 5, 2013 04:42
This snippet of Google Apps-Script was written in response to StackOverflow question 15187688, where the user was looking for a way to obtain a contiguous range of cells - a group of cells that contained values, but which was smaller than the range that would result from calling getDataRange().
function testRanges() {
var range1 = getContiguousRange("C3").getA1Notation();
var range2 = getContiguousRange("B8").getA1Notation();
debugger;
}
/**
* Return the contiguous Range that contains the given cell.
*
@mogsdad
mogsdad / appsScriptSaveSpeed.js
Created March 1, 2013 15:05
This gist contains a Google Apps Script that performs some experiments to provide comparisons between data storage options. It was written in response to StackOverflow question [What is faster: ScriptDb or SpreadsheetApp?](http://stackoverflow.com/questions/15145918/what-is-faster-scriptdb-or-spreadsheetapp)
/**
* Run experiments to measure speed of various approaches to saving data in
* Google App Script (GAS).
*/
function testSpeed() {
var numObj = 400;
var numAttr = 10;
var doFlush = false; // Set true to activate calls to SpreadsheetApp.flush()
var arr = buildArray(numObj,numAttr);