GMail TODO Script

After reading GMail Snooze with Apps Script I thought "Gosh, that's almost what I need to make GMail my go-to TODO list platform." Well, I finally sat down and closed the gap.

var MARK_UNREAD = true;
var MARK_IMPORTANT = true;
var ADD_TODO_LABEL = true;
var TIMEZONE = "EST";

function setup() {
  if (ADD_TODO_LABEL) {
    GmailApp.createLabel("TODO");
  }
}

function reviveTODOs() {
  var todayString = Utilities.formatDate(new Date(),
     TIMEZONE, "yyyy/MM/dd");
  var todaysLabel = 
     GmailApp.getUserLabelByName(todayString);  
  var page = null;

  // Get threads in "pages" of 100 at a time
  while(todaysLabel 
      && (!page || page.length == 100)) {
    page = todaysLabel.getThreads(0, 100);

    if (page.length > 0) {
      GmailApp.moveThreadsToInbox(page);
      
      if (MARK_UNREAD) {
        GmailApp.markThreadsUnread(page);
      }

      if (MARK_IMPORTANT) {
        GmailApp.markThreadsImportant(page);
      }
      
      if (ADD_TODO_LABEL) {
        GmailApp.getUserLabelByName("TODO")
          .addToThreads(page);
      }          
    }     
  }
}

Instead of using "Snooze x Days" labels, I use date labels like "2011/08/11" to remind myself to follow up on bills, respond to emails, etc. With this modified version of Corey Goldfeder's script, I don't have to remember to check those labels, they just pop back into my inbox automatically. I had a little problem with the markThreadsImportant call not seeming to work. Don't know what's up with that. But otherwise, it has performed well so far in testing.

Update: Be sure to set the timezone that the script will run in and the timezone used to format date labels to the same timezone. See Using Time-Driven Triggers.

Like this script? Have your own variation? Please share!

No comments:

Post a Comment