Skip to content

Instantly share code, notes, and snippets.

@westonruter
Last active November 10, 2023 22:24
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save westonruter/4528421 to your computer and use it in GitHub Desktop.
Save westonruter/4528421 to your computer and use it in GitHub Desktop.
Google Apps Script for Gmail to automatically forward Google Now notes to self onto Remember the Milk

Google Apps Script for Gmail to automatically forward Google Now notes to self onto Remember The Milk, transforming the transcribed speech into Smart Add syntax, and then archiving the thread in Gmail. Create a new script in Google Drive for Gmail, paste this JS into it, customize the rtm_email variable to your own, and customize the transformations to rtm_task for Smart Add to fit your style, and then set up a trigger to invoke the function every minute. Within approximately a minute after sending yourself a note via Google Now, the reminder will be added to your RTM account!

Example dictation: Note to self to look up article about widgets for work priority 1
Smart Add transformation: Look up article about widgets #work !1

Resources

function forwardAndArchiveGoogleNowReminderstoRTM() {
var rtm_email = 'jsmith+abc123@rmilk.com';
var from_email = Session.getActiveUser().getEmail();
var threads = GmailApp.getInboxThreads();
for (var i = 0; i < threads.length; i++) {
var messages = threads[i].getMessages();
for (var j = 0; j < messages.length; j++) {
var is_from_self = messages[j].getFrom().indexOf(from_email);
if (messages[j].getSubject() === 'Note to self' && is_from_self) {
var rtm_task = messages[j].getBody();
rtm_task = rtm_task.replace(/<\/?\w+[^>]*>/g, ''); // strip out all HTML tags
// Customize these replacements to transform your speech into Smart Add syntax
// Example: Note to self priority one check the PHP code sniffer rules for work
// => !2 to check the PHP code sniffer rules #Work
rtm_task = rtm_task.replace(/\b(and )?on list\s+/, '#');
rtm_task = rtm_task.replace(/\b(and )?with tag\s+/i, '#');
rtm_task = rtm_task.replace(/\bfor work/i, '#Work');
rtm_task = rtm_task.replace(/(^|(and|with) )?(bang|priority) (1|one|won)\b/i, '!1');
rtm_task = rtm_task.replace(/(^|(and|with) )?(bang|priority) (2|two|too|to)\b/i, '!2');
rtm_task = rtm_task.replace(/(^|(and|with) )?(bang|priority) (3|three)\b/i, '!3');
rtm_task = rtm_task.replace(/^to /i, '');
rtm_task += ' ^today';
GmailApp.sendEmail(rtm_email, rtm_task, '');
GmailApp.moveThreadToArchive(threads[i]);
Logger.log(rtm_task);
}
}
}
}
@fredclown
Copy link

I like this script! I might set it up myself. I've been using this regex for html these days ... it will not break if there is a ">" within an attribute. Such as ...

<img title="An image about a >" src="angle.gif" />

It's not perfect I'm sure, but it catches a few other cases.

</?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)/?>

@gleitz
Copy link

gleitz commented Jan 14, 2013

How do you choose when the script is run?

@westonruter
Copy link
Author

@gleitz I have the script triggered to run every minute.

Copy link

ghost commented Sep 26, 2013

What a great script! Thank you

Copy link

ghost commented Sep 27, 2013

Thanks very much for the inspiration! I adapted your script to work with Remember The Milk and Evernote simultaneously: https://gist.github.com/CodeCrimp/6728080

@claytron
Copy link

Very nice!

It was kind of confusing on how to get it all set up. Here is what I did:

  • Go to https://script.google.com/
  • Add the script from the gist
  • Change the RTM email address to be mine
  • Save the script
  • Publish -> Deploy as Web App (not sure if this step was necessary)
  • Resources -> Current project's triggers
    • Set up a Time-Driven trigger for a certain interval of hours or minutes

Then I tested that everything was working. If you have issues, you can manually run the script at any time, but it will only work its magic once the trigger is set up.

@davisnrjr
Copy link

No Comments since - claytron commented on Nov 19, 2013
Any approach better, cleaner, faster?

@BevanR
Copy link

BevanR commented Apr 7, 2016

Does this work with Google Now Reminders?

@mzguy
Copy link

mzguy commented Nov 10, 2023

@westonruter I've been using this idea for years, with many of my personal modifications. However, a big problem is that I can no longer get my Android Google Assistant to write an email. It appears Google changed the functionality such that as of a few months ago, trying to send an email results only in "Opening Gmail..." Have you found a workaround?

@westonruter
Copy link
Author

@mzguy Sorry, I completely forgot I wrote this as I haven't been using it for many years. I'm not aware of the latest here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment