3

Summary: I would like to create some sort of an automated process where any messages that I 'star' in Gmail (aka 'flag' when using Gmail via IMAP) will automatically be added to OmniFocus, and then "unstarred" on Gmail and moved to another specific label called "OmniFocus".

I am quite sure that this is possible with Google Scripts but I cannot figure out how to get it to work. I would like that solution because it would not require me to run anything else on my own Mac.

Also: I have an account with http://www.spootnik.net which means that I can add things to my OmniFocus Inbox by sending email to a specific email address.

My idea for a Google Script would go something like this:

  • every ¿15? minutes or so, check for flagged messages in Gmail, and if found:
  • forward to my Super Secret Spootnik Email Address
  • Add label 'OmniFocus' to message
  • unstar/unflag message in Gmail

Unfortunately I don't know to make this work in Google Scripts, so I'm wondering if someone else might know and be able to explain it to others who might want to do something similar.

Alternatively

While I would prefer Google Scripts, I do have a Mac which is usually on 24/7 anyway, so if that is the only way to do this, that would also be an option. Unfortunately I have even less of an idea how to do that. (I assume Mail.app + AppleScript?)

2
  • would ifttt.com be an option as well?
    – nohillside
    Apr 8, 2013 at 20:25
  • That's a good thought but I couldn't make it work. It can trigger off a new flagged message but not do something with that message itself.
    – TJ Luoma
    Apr 9, 2013 at 2:21

1 Answer 1

4

Try:

function TJ() {
  var threads = GmailApp.search('label:inbox is:starred');
  for (var h = 0; h < threads.length; h++) {
    var messages = threads[h].getMessages();
    for (var i = 0; i < messages.length; i++) {
      if (messages[i].isStarred())
      {
        Logger.log(messages[i].getSubject());
        messages[i].unstar();
        messages[i].forward("[email protected]", {
          // Advanced parameters: https://developers.google.com/apps-script/reference/gmail/gmail-message#forward%28String,Object%29
          cc: "[email protected]",
          bcc: "[email protected],[email protected]"
          });     
      }
  }
}
}

For more information regarding Google Apps Script, see this post: http://www.johneday.com/422/time-based-gmail-filters-with-google-apps-script

1
  • Yes! This worked perfectly. I used the "CC:" to send it to myself "[email protected]" and then created a rule which automatically marked that as read and applied the label "omnifocus" to it. Thanks again!
    – TJ Luoma
    Apr 9, 2013 at 14:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .