My wife receives emails with substitute teaching assignments. My goal is to automate the conversion of those emails into calendar events by parsing out the relevant information from the emails.
I have an Applescript that I shamelessly borrowed from the web (knowing nothing about Applescript until a few days ago) and tweaked until it worked for everything...except the dates. To simplify this post I've stripped out most of the code except for one section that works and a section that doesn't;hopefully somebody will be able to tell me how to get a date to work.
The email content contains lines that looks like the following:
Using the code below I successfully converted the "Location" line into the location field of the event. However, when I tried parsing out the date info, creating a string, and then turning that into a date, I get errors at "date (myStartMonth & "/" & myStartDay & "/" & myStartYear)". The error reads Microsoft Outlook got an error: Cant get date "03/11/2014". However, if actually replace the line with date ("03/11/2014") it works fine. It's the combining of strings that is failing.
The odd thing is a similar construct worked fine a standalone code...it appears to fail when inside the "Tell application" line.
Any help on how to fix this and successfully convert the start date text into an Applescript date would be gratefully appreciated.
Thanks
Rossdillon
I have an Applescript that I shamelessly borrowed from the web (knowing nothing about Applescript until a few days ago) and tweaked until it worked for everything...except the dates. To simplify this post I've stripped out most of the code except for one section that works and a section that doesn't;hopefully somebody will be able to tell me how to get a date to work.
The email content contains lines that looks like the following:
Code:
Location: MOORE, WILLIAM ES
Start Date: 2014-03-11
End Date: 2014-03-11
Using the code below I successfully converted the "Location" line into the location field of the event. However, when I tried parsing out the date info, creating a string, and then turning that into a date, I get errors at "date (myStartMonth & "/" & myStartDay & "/" & myStartYear)". The error reads Microsoft Outlook got an error: Cant get date "03/11/2014". However, if actually replace the line with date ("03/11/2014") it works fine. It's the combining of strings that is failing.
The odd thing is a similar construct worked fine a standalone code...it appears to fail when inside the "Tell application" line.
Any help on how to fix this and successfully convert the start date text into an Applescript date would be gratefully appreciated.
Thanks
Rossdillon
Code:
tell application "Microsoft Outlook"
repeat with theMessage in selectedMessages
set theContent to content of theMessage
set theCategory to category of theMessage
-- Find the location from the email
set mylocation to {}
repeat with aParagraph in (paragraphs of theContent)
set aParagraph to contents of aParagraph
if aParagraph begins with "Location:" then
set the end of mylocation to text (word 2 of aParagraph) thru -1 of aParagraph
exit repeat
end if
end repeat
--end repeat
set theLocation to mylocation
-- Find the "Start date" from the email
repeat with aParagraph in (paragraphs of theContent)
set aParagraph to contents of aParagraph
if aParagraph begins with "Start Date:" then
set myStartMonth to (characters 18 thru 19 of aParagraph) as string
set myStartDay to (characters 21 thru 22 of aParagraph) as string
set myStartYear to (characters 13 thru 16 of aParagraph) as string
set myStartDate to date (myStartMonth & "/" & myStartDay & "/" & myStartYear)
exit repeat
end if
end repeat
set newEvent to make new calendar event with properties {all day flag:true, subject:theName, category:theCategory, content:theContent, location:theLocation, start time:myStartDate, end time:myEndDate}
open newEvent
end repeat
end tell