Advertisement
Guest User

Untitled

a guest
May 27th, 2017
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Triggered by Airmail rule.
  2. on processMessage(theMessage)
  3.     try
  4.         tell application "Airmail 2"
  5.             set {name, cert, guest, addr, starttime} to my parseMsg(theMessage)
  6.             my createEvent(name, cert, guest, addr, starttime)
  7.         end tell
  8.     on error e
  9.         display dialog (e as string)
  10.     end try
  11. end processMessage
  12.  
  13. --Parse the email content to extract tour details.
  14. on parseMsg(theMessage)
  15.     set name to extractBetween(theMessage, "Name: ", "Confirmation: ")
  16.     set cert to extractBetween(theMessage, "Confirmation: ", "Guest: ")
  17.     set guest to extractBetween(theMessage, "Guest: ", "Address: ")
  18.     set addr to extractBetween(theMessage, "Address: ", "Time: ")
  19.     set datestring to extractBetween(theMessage, "Time: ", "Stop")
  20.     set starttime to parseDateString(datestring)
  21.     return {name, cert, guest, addr, starttime}
  22. end parseMsg
  23.  
  24. -- Parse date and time from the string given in the email.
  25. on parseDateString(datestring)
  26.     set theDate to current date
  27.     set dateWords to words of datestring
  28.     set day of theDate to text 1 thru -3 of item 2 of dateWords
  29.     set time of theDate to (item 5 of dateWords) * hours + (item 6 of dateWords) * minutes
  30.     set monthList to {January, February, March, April, May, June, July, August, September, October, November, December}
  31.     repeat with i from 1 to 12
  32.         if item 3 of dateWords = ((item i of monthList) as string) then
  33.             set monthNumber to (text -2 thru -1 of ("0" & i))
  34.             exit repeat
  35.         end if
  36.     end repeat
  37.     set month of theDate to monthNumber
  38.     return theDate
  39. end parseDateString
  40.  
  41. --Create a calendar event for the specified tour.
  42. on createEvent(name, cert, guest, addr, starttime)
  43.     tell application "Calendar" to tell calendar "Home"
  44.         set theEvent to make new event with properties {start date:starttime, summary:"Tour:" & name & guest}
  45.         set location of theEvent to "Winery" & addr
  46.         set description of theEvent to "Certification 3:" & cert
  47.     end tell
  48. end createEvent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement