Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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?)

share|improve this question
    
would ifttt.com be an option as well? –  patrix Apr 8 '13 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 '13 at 2:21

1 Answer 1

up vote 2 down vote accepted

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("recipient1@example.com", {
          // Advanced parameters: https://developers.google.com/apps-script/reference/gmail/gmail-message#forward%28String,Object%29
          cc: "myboss@example.com",
          bcc: "mybosses-boss@example.com,vp@example.com"
          });     
      }
  }
}
}

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

share|improve this answer
    
Yes! This worked perfectly. I used the "CC:" to send it to myself "example+omnifocus@gmail.com" and then created a rule which automatically marked that as read and applied the label "omnifocus" to it. Thanks again! –  TJ Luoma Apr 9 '13 at 14:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.