Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Triggered by Airmail rule.
- on processMessage(theMessage)
- try
- tell application "Airmail 2"
- set {name, cert, guest, addr, starttime} to my parseMsg(theMessage)
- my createEvent(name, cert, guest, addr, starttime)
- end tell
- on error e
- display dialog (e as string)
- end try
- end processMessage
- --Parse the email content to extract tour details.
- on parseMsg(theMessage)
- set name to extractBetween(theMessage, "Name: ", "Confirmation: ")
- set cert to extractBetween(theMessage, "Confirmation: ", "Guest: ")
- set guest to extractBetween(theMessage, "Guest: ", "Address: ")
- set addr to extractBetween(theMessage, "Address: ", "Time: ")
- set datestring to extractBetween(theMessage, "Time: ", "Stop")
- set starttime to parseDateString(datestring)
- return {name, cert, guest, addr, starttime}
- end parseMsg
- -- Parse date and time from the string given in the email.
- on parseDateString(datestring)
- set theDate to current date
- set dateWords to words of datestring
- set day of theDate to text 1 thru -3 of item 2 of dateWords
- set time of theDate to (item 5 of dateWords) * hours + (item 6 of dateWords) * minutes
- set monthList to {January, February, March, April, May, June, July, August, September, October, November, December}
- repeat with i from 1 to 12
- if item 3 of dateWords = ((item i of monthList) as string) then
- set monthNumber to (text -2 thru -1 of ("0" & i))
- exit repeat
- end if
- end repeat
- set month of theDate to monthNumber
- return theDate
- end parseDateString
- --Create a calendar event for the specified tour.
- on createEvent(name, cert, guest, addr, starttime)
- tell application "Calendar" to tell calendar "Home"
- set theEvent to make new event with properties {start date:starttime, summary:"Tour:" & name & guest}
- set location of theEvent to "Winery" & addr
- set description of theEvent to "Certification 3:" & cert
- end tell
- end createEvent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement