Submissions Script for Fireside Magazine

Below is the script I used to save files to Google Drive. It was originally created by Amit Agarwal, and modified slightly by me to create additional copies and write to a spreadsheet, including reader assignments. Amit’s tutorial also demonstrates how to install this script, so rather than recreate it, I recommend you check out his site. Apologies for the formatting, but I wanted to post the entire script and WordPress security prevented me from uploading the script as an attachment.


Send to Google Drive by Digital Inspiration, modified by Matt White for Fireside Magazine

tutorial : (and original code)

contact :
twitter : @labnol


1. Fetch 5 messages at a time to prevent timout
2. Folder logic moved to a separate function
3. Better status messages

function sendToGDrive() {

var sheet = SpreadsheetApp.getActiveSheet();
var gLabel = “submissions”;
var gFolder = “August 2012”;
var gFolderAnon = “August 2012 Anon”;
var readers = [“Reader One”,”Reader Two”,”Reader Three”];

var threads =“label:” + gLabel, 0, 5);
var folder = DocsList.getFolder(gFolder);
var folderAnon = DocsList.getFolder(gFolderAnon);

for (var x=0; x<threads.length; x++) {

var messages = threads[x].getMessages();

for (var y=0; y<messages.length; y++) {

var att = messages[y].getAttachments();
var message = messages[y];
var from = message.getFrom();

for (var z=0; z<att.length; z++) {
try {
var folderFiles = DocsList.getFolder(gFolder).getFiles();
var readerIndex = folderFiles.length%readers.length
var file = folder.createFile(att[z]);
var fileAnon = folderAnon.createFile(att[z]);
var row = SpreadsheetApp.getActiveSheet().getLastRow();
catch (e) {
GmailApp.sendEmail(“”,”system error”, e.message);

function configure() {
var sheet = SpreadsheetApp.getActiveSheet();
var gLabel = “submissions”;

if (!GmailApp.getUserLabelByName(gLabel)) {

if (ScriptApp.getScriptTriggers().length == 0) {

.toast(“You can now close this Google Docs sheet and it will run in the background.”,
“Success”, -1);

function onOpen() {
var menu = [
{name: “Initialize”, functionName: “configure”},
{name: “Run”, functionName: “configure”}
.addMenu(“Submissions”, menu);


One thought on “Submissions Script for Fireside Magazine

  1. Pingback: The Fireside Magazine Submissions Process | geekstarter

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s