Forums

Discuss all things Remember The Milk.

Automate Remember the Milk through Google Calendar and Google Apps Script

jorg3cardoso says:
I always missed one particular feature for RTM: being able to make a task show up only after a pre-defined date. I would like this feature because there are tasks that one can only complete after a particular day (for example, pick up the results from the last medical exams). There are two options to deal with this:

1. Just put the task in RTM anyway. The problem with this is that the task can't really be completed until after the day the exams will be ready. So, until that day, it will just be polluting your task list. Even if you use RTM with some GTD structure and mark the task as being in a wait list, I still don't like having tasks that are waiting for a particular day. It seems the kind of thing that you should not have to do: it's pretty straightforward for a computer to check if a given day has arrived and make a task show up.

2. Don't put the task in RTM; instead put a note in your calendar in the day the exams will be ready. When that day comes, your calendar will alert you and you can put the task in RTM. This is better for me, but this manual operation of transferring an event from the calendar to RTM always nagged me.

So, recently, I found out about Google Apps Script. Basically, this allows you to create scripts attached to Google spreadsheets in Google Docs. The script language allows you to access most of Google's data. The feature that is of interest here is that you can trigger scripts to run, based on timed events. In essence, what I did was:

1. Create a timed script that runs once a day. I created a new Google spreadsheet named Scripts and added a script to the spreadsheet (Tools->Scripts->Script Editor)

2. The script accesses my calendar and looks for events in that day. The script is just this:

function myFunction() {
var cal = CalendarApp.getDefaultCalendar();

var today = new Date();

var todayEvents = cal.getEventsForDay(today);

for (var i = 0; i < todayEvents.length; i++) {
var title = todayEvents[i].getTitle();
if (title.indexOf("RTM") == 0) {
MailApp.sendEmail("myrtmemailaddress", title.substr(3), todayEvents[i].getDescription());

}
}

}​

3. I created a daily trigger to run the script at 1am.

4. If the event is named "RTM something" it picks up the event description and sends an email to my RTM email address.

With this script I can just enter an event for the day the exams will be ready and when that day comes, a task will show up automatically in my RTM list. In order to fill in the task in the right list and with the right tags I format the description of the event using RTM's emailed task language.

In my case I use my default calendar for these RTM tasks, but you could create a dedicated calendar for this. You would just need to change the script to:

function myFunction() {
var cal= CalendarApp.getCalendarById("calendarid");
var today = new Date();

var todayEvents = cal.getEventsForDay(today);

for (var i = 0; i < todayEvents.length; i++) {
var title = todayEvents[i].getTitle();
if (title.indexOf("RTM") == 0) {
MailApp.sendEmail("myrtmemailaddress", title.substr(3), todayEvents[i].getDescription());

}
}

}​

(you can get the calendar id in the Calendar details in the settings page.)
Posted at 8:58pm on January 4, 2011
rossgoodman says:
Awesome idea - I may "borrow" your code for a couple of other ideas!
For those intimidated by scripting have a look at www.iftt.com (If This Then That) using your calendar as a trigger and EMail as the action.
Posted 11 years ago
raymond.bergmark Power Poster says:
Minor link error, it's www.ifttt.com which is an excellent and creative service, well worth checking out.
Posted 11 years ago
raymond.bergmark Power Poster says:
Another idea (should have read the original post before posting above) is to use the sleeper tag method described here:
http://blog.rememberthemilk.com/2009/04/tips-tricks-tuesday-using-sleeper-tags/

That way you can add tasks to your task list, but they will not appear in your smart lists until a certain number of days/weeks/months before it's due.

However, it doesn't work for things like "after exam" unless you have the exam date as the due date, meaning it immediately becomes overdue if you use tag zzz (see the blog post for an explanation).
Posted 11 years ago
raymond.bergmark Power Poster says:
Additional idea: Could you use the method above to check if a certain task has been completed and add the task after that? Would probably have to use the API I guess, maybe a bit complicated.

That way it would be possible to implement task dependencies, probably the most requested feature here at RTM (after having a proper calendar on the website and having the ability to add the key should you at some point mistakenly closed it.)
Posted 11 years ago
raymond.bergmark Power Poster says:
Fourth post in a row, should have been first: Excellent idea jorg3cardoso, clever method!
Posted 11 years ago
raymond.bergmark Power Poster says:
Fifth ;-)

Tried this, it worked right away, I'm really impressed by the cleverness of this! Especially combined with the smart add syntax making it possible to have all the task details filled out.

Well worth a Tip of the Week mention! Sadly, it seems that RTM mostly acknowledges less technical tips&tricks in their weekly blog posts.
Posted 11 years ago
raymond.bergmark Power Poster says:
Sixth...

Not really RTM, but it's possible to use this method in order to send future e-mails through Gcal as well with some modifications:

function sendFutureEmail() {
var cal = CalendarApp.getDefaultCalendar();
// or maybe var cal= CalendarApp.getCalendarById("calendarid");
var today = new Date();
var todayEvents = cal.getEventsForDay(today);

for (var i = 0; i < todayEvents.length; i++) {
var title = todayEvents[i].getTitle();
if (title.indexOf("Email") == 0) {
var blanks = title.substr(6).search(" ");
MailApp.sendEmail(title.substr(6, blanks), title.substr(6 + blanks + 1), todayEvents[i].getDescription());
}
}
}​

A typical entry in Gcal would be:
Email xxx@yyy.com This is the subject

In the description field for this entry you write the message text including your signature.

You may want to change the time for this script to say 07:00 or similar.
Posted 11 years ago
Log in to post a reply.