Using OS X El Capitan.
First TIA for any help you might be able to provide.
I am trying to set up a script that will:
(1) extract information from a form notification I receive; and
(2) create a calendar event based upon the extracted information.
The email looks like this:
Notification.
John Doe at AL - Gulf Shores …
I need to create a mail rule that basically says: If email contains “Notification”, then run applescript “the script”; “the script” would then extract the name “John Doe”, the location Gulf Shores, and create a calendar event title “John Doe” with a start and end date of the date the email is received with an alert repeating on three occasions after the start date: 90 days after, 180 days after, and 360 days after.
Using cinema.scpt, here’s what I have so far:
-- Triggered by Mail rule.
using terms from application "Mail"
on perform mail action with messages msgs for rule theRule
tell application "Mail"
repeat with msg in msgs
try
set msgcontent to content of msg
set msgid to message id of msg
set {person, addr} to my parseMsg(msgcontent)
my createEvent(person, addr)
end try
end repeat
end tell
end perform mail action with messages
end using terms from
-- Parse the email content to extract movie details.
on parseMsg(msgcontent)
set person to extractBetween(msgcontent, "Notification. ", “- ")
set addr to extractBetween(msgcontent, "AL - ", ".")
return {person, addr}
end parseMsg
-- Create a calendar event for the specified movie.
on createEvent(person, addr)
set endtime to starttime + mins * minutes
tell application "Calendar" to tell calendar “calendar”
set theEvent to make new event with properties {start date:current date, end date:current date, summary:"person: " & person & addr}
set location of theEvent to addr
set description of theEvent to "person: " & person & addr
end tell
end createEvent
-- Extract the substring from between two strings
to extractBetween(theString, startText, endText)
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to startText
set startComps to text items of theString
set AppleScript's text item delimiters to endText
set endComps to text items of second item of startComps
set AppleScript's text item delimiters to tid
return trim(first item of endComps)
end extractBetween
-- Trim all whitespace from start and end of a string
on trim(theString)
set theChars to {" ", tab, character id 10, return, character id 0, character id 8232}
repeat until first character of theString is not in theChars
set theString to text 2 thru -1 of theString
end repeat
repeat until last character of theString is not in theChars
set theString to text 1 thru -2 of theString
end repeat
return theString
end trim
-- 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
Alvin L. Moon
The Moon Law Firm
31138 Wakefield Drive
Spanish Fort, Alabama 36527
Tel. Spanish Fort: 251.767.4302
Tel. NOLA: 504.343.3774
Fax 251.272.4203
email@hidden
www.themoonlawfirm.com
ANY ADVICE CONTAINED IN THIS MESSAGE WAS NOT WRITTEN OR INTENDED TO BE AND CANNOT BE, USED, BY ANY TAXPAYER FOR THE PURPOSE OF AVOIDING PENALTIES WITH RESPECT TO TAXES. (SEE IRS CIRCULAR 230). UNLESS OTHERWISE EXPRESSLY STATED HEREIN, NOTHING CONTAINED HEREIN IS INTENDED TO CREATE A CONTRACT UNDER ANY ELECTRONIC SIGNATURE OR SIMILAR LAW.
THE INFORMATION CONTAINED IN THIS TRANSMISSION IS INTENDED FOR USE ONLY BY THE ADDRESSEE AND MAY BE PRIVILEGED, CONFIDENTIAL, AND/OR PROTECTED FROM DISCLOSURE AS AN ATTORNEY/CLIENT COMMUNICATION OR ATTORNEY WORK PRODUCT. ANY USE, DISTRIBUTION, OR DUPLICATION OF IT IS PROHIBITED WITHOUT THE CONSENT OF THE SENDER OR THE ADDRESSEE. IF YOU RECEIVED THIS E-MAIL IN ERROR, PLEASE IMMEDIATELY NOTIFY US BY E-MAIL OR AT THE TELEPHONE ADDRESS LISTED ABOVE FOR INSTRUCTIONS ON FURTHER HANDLING.