Skip to content

Instantly share code, notes, and snippets.

@mhawksey
mhawksey / include-snippet.gs
Created October 23, 2017 22:16
Apps Script exerpt to include images in HTML Service
/**
* given an image object, it will generate an img tag
* @param {Object} imgData with image data
* @return {string} of img tag or src
*/
ns.img = function (imgData, isImgTag) {
if (!isImgTag){
var html = '<img ';
Object.entries(imgData).forEach(function(k){ html += k[0]+'="'+k[1]+'" '});
html += '>\n'
@mhawksey
mhawksey / YouTubeOAuth2Service.gs
Last active October 26, 2020 20:32
YouTube service setup for use with OAuth2 for Apps Script https://github.com/googlesamples/apps-script-oauth2
/* Setup
1. In the Script Editor select Resources > Cloud platform project... and click the link to the currently associated project
2. In the Google Cloud Platform window click "Go to APIs overview"
3. In APIs & services click "Enable APIs and Services"
4. In the Library search/click on YouTube Data API and click 'Enable'
@mhawksey
mhawksey / youtube.gs
Last active September 15, 2022 16:29
YouTube API for Google Apps Script
/**
* Google Apps Script Library for the youtube API
*
* Documentation can be found:
* https://developers.google.com/youtube/v3
*
* OAuth2 Scopes
* https://www.googleapis.com/auth/youtube
* https://www.googleapis.com/auth/youtube.force-ssl
@mhawksey
mhawksey / Code.gs
Last active November 17, 2019 07:53 — forked from matthewrknoll/Code.gs
Automatically include your latest favorited Tweet in your Gmail signature. More info https://knoll.tech/2017/01/24/automatically-include-your-latest-tweet-in-your-gmail-signature/
// Grabs my latest tweet favorited using the handy TwtrService wrapper by +MartinHawksey - https://goo.gl/2it7yb
function getLatestTweet() {
var data = TwtrService.get("statuses/user_timeline", {screen_name: /*"YourTwitterHandle(without the @)"*/, count: 1});
var id = false;
for (var i = 0; i < data.length; i++){
if (data[i].favorited) {
id = data[i].id_str;
break;
}
}
@mhawksey
mhawksey / slide_template.gs
Last active March 23, 2021 10:54
Port of Wesley Chun's 'Using the Google Slides API with Python' to Google Apps Script. Read more at https://mashe.hawksey.info/?p=17385
// Port of Slides API demo by Wesley Chun to Google Apps Script
// Source: http://wescpy.blogspot.co.uk/2016/11/using-google-slides-api-with-python.html
function slides_template() {
/*
from apiclient import discovery
from httplib2 import Http
from oauth2client import file, client, tools
*/
function showRow(doc){
var cache = getCache_();
try {
// if cache is set and id matches handle open row for editing
if (cache.id && cache.id === doc.getId()){
doc.toast("Opened on row for editing...");
var sheet = doc.getSheetByName(cache.sheet);
if (sheet != null) {
if(cache.row){
function doGet(e) {
var html = HtmlService.createTemplateFromFile('index');
html.e = e.parameter;
return html.evaluate().setTitle('Opening a row...');
}
function setCache(parameter){
var values = {
'row': parameter.row,
'header':parameter.header,
@mhawksey
mhawksey / index.html
Created October 17, 2016 19:38
open row
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
var e = <?!= JSON.stringify(e) ?>;
google.script.run.withSuccessHandler(onSuccess).setCache(e);
function onSuccess(url){
window.top.location.href = url;
@mhawksey
mhawksey / sendvotes.gs
Last active March 27, 2020 20:08
Short Google Apps Script snippet that pushes from:, subject and date to a Google Sheet (designed to be triggered frequently). I use the snippet to collect votes sent via email
function myFunction() {
try {
var out = [];
if (GmailApp.getInboxUnreadCount() > 0 ){
var threads = GmailApp.getInboxThreads();
for (var i = 0; i < threads.length; i++) {
out.push([threads[i].getMessages()[0].getFrom(), threads[i].getFirstMessageSubject(), threads[i].getMessages()[0].getDate()]);
threads[i].moveToArchive();
}
@mhawksey
mhawksey / application.js
Last active September 16, 2016 09:53
Twitter Archive application.js fix to show relative dates/times
var Grailbird = function (type, date, data) {
Grailbird.data = Grailbird.data || {};
Grailbird.data[type+'_'+date] = data;
};
(function(exports) {
"use strict";
var User = {},
Tweets = {},