AppleScript to TEXT me when certain emails come in

Discussion in 'Mac Programming' started by John Greer, Jan 30, 2012.

  1. John Greer, Jan 30, 2012
    Last edited: Feb 1, 2012

    macrumors member

    John Greer

    Joined:
    Jun 20, 2011
    Location:
    Wayne, NJ USA
    #1
    Currently, I have a Mail Rule that forwards certain emails to me, via SMS text.
    It comes over unformatted for text, very ugly and hard to read.
    I would like an AppleScript to send me a text that only has FROM and SUBJECT. Once I see that, I can get the rest form my iPhone. I just don't want to miss these emails.

    All I really need is a script that can "read" the FROM, SUBJECT, SENT_TIME and SENT_DATE. From that, I can then create a new email (assuming I figure out how) and send that to my phone.

    Has anyone already written this script?
     
  2. thread starter macrumors member

    John Greer

    Joined:
    Jun 20, 2011
    Location:
    Wayne, NJ USA
    #2
    So I got this to work in the AppleScript Editor:
    Code:
    tell application "Mail"
              set newMsg to make new outgoing message
              set content of newMsg to "Test Message from Mail2text.scpt"
              set sender of newMsg to "someone"
              set subject of newMsg to "Test"
              tell newMsg
      make new to recipient at end of to recipients with properties {address:"mynumber@txt.att.net"}
      send
              end tell
      --set visible of newMsg to true
      --display dialog theContent
      --say theContent
    end tell
    but I cannot get it to work via a rule:
    Code:
    using terms from application "Mail"
              on perform mail action with messages theSelectedMessages for rule theRule
                        tell application "Mail"
                                  repeat with eachMessage in theSelectedMessages
                                            tell eachMessage
                                                      set f to sender of eachMessage
                                                      set s to subject of eachMessage
                                                      set ds to date sent of eachMessage
                                                      set dr to date received of eachMessage
      --say theContent
      --display dialog theContent
                                                      set newMsg to make new outgoing message
                                                      set sender of newMsg to f
                                                      set subject of newMsg to s
                                                      set content of newMsg to "Message from" & sender & " sent:" & date sent & ", received:" & date received
                                                      tell newMsg
      make new to recipient at end of to recipients with properties {address:"mynumber@txt.att.net"}
                                                                send
                                                      end tell
      --set visible of newMsg to true
      --display dialog theContent
      --say theContent
                                            end tell
                                  end repeat
                        end tell
              end perform mail action with messages
    end using terms from
     
  3. macrumors member

    Joined:
    Aug 28, 2008
    #3
    Wirelessly posted (Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3)

    I've done this before with gmail (pretty simple). I think it makes more sense to set this up at the mail server end, rather than in your mac. What if you Mac is off or not connected, etc?
     

Share This Page