I have a script that I would like to enhance. I would like to reference the time and date references within the email to create the Start Date event in ICal. Following is the email content. Also, golf course name may have up to three words.
Email: FOR MIKE VAN METER, request number 709942: you have a tee time reserved for SUNDAY, 04/18/2010 on the SANDHILL golf course at 12:08. Your reservation number is 753766.
Regards,
Following is present script.
Open this Scriplet in your Editor:
tell application "Mail"
set mboxName to "Comcast"
set thePrefix to "Tee Time"
set theMessages to (messages of inbox whose subject is "Tee Time")
repeat with mail in theMessages
if the subject of the mail begins with thePrefix then
set theSummary to word 21 of the content of the mail
set theDescription to the content of the mail
set theStartDate to the date received of the mail
end if
end repeat
tell application "iCal"
set theCalendar to "Calendar"
tell calendar theCalendar to make new event at end of events with properties {summary:theSummary, description:theDescription, start date:theStartDate + 3 * days}
end tell
end tell
tell application "Mail"
set mboxName to "Tee Time"
set thePrefix to "Tee Time"
repeat with mail in theMessages
if the subject of the mail begins with thePrefix then
move theMessages to mailbox mboxName
end if
end repeat
set read status of the mail to true
end tell
try this, it’s quite independent from length of names.
It assumes that the following terms are always included in the text:
“reserved for "
" on the "
“. "
" golf course”
" at”
And it assumes also US date format settings (in International PrefPane)
set mboxArchiveName to "Tee Time"
set thePrefix to "Tee Time"
tell application "Mail" to set theMessages to (messages of inbox whose subject is thePrefix)
repeat with oneMessage in theMessages
tell application "Mail" to set theDescription to the content of oneMessage
set {TID, text item delimiters} to {text item delimiters, "reserved for "}
set theContent to text item 2 of theDescription
set text item delimiters to ". "
set theContent to text item 1 of theContent
set text item delimiters to " on the "
set theDate to text item 1 of theContent
set theCourse to text item 2 of theContent
set text item delimiters to " golf course"
set theSummary to text item 1 of theCourse
set text item delimiters to " at "
set theTime to text item 2 of theContent
set text item delimiters to ":"
set {hr, mn} to text items of theTime
set text item delimiters to TID
set theStartDate to date theDate
tell theStartDate to set {its hours, its minutes} to {hr, mn}
tell application "iCal"
set theCalendar to "Calendar"
tell calendar theCalendar to make new event at end of events with properties {summary:theSummary, description:theDescription, start date:theStartDate + 3 * days}
end tell
tell application "Mail"
set read status of the oneMessage to true
move oneMessage to mailbox mboxArchiveName
end tell
end repeat
Stefan, Thanks for you help with this project. Script runs great except for the :tell theStartDate to set {its hours, its minutes} to {hr,mn} statement. It will error out with comment “Can’t make "50. Your reservation number is 767545. " into type integer” number -1700 from "50.Your reservation number is 767545. "to integer
Commenting out that statement, it will run fine and default to 12:00
This script is way above my present skill level, so i will study it closely. I appreciate your help.
Regards,
Mike Van Meter
Model: IMac
AppleScript: 2.3(118)
Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)
The following is the final cut with thanks to StefanK Note first post does not contain “starting on hole” phrase. Some tee times have that info. Good luck
set mboxArchiveName to "Tee Time"
set thePrefix to "Tee Time"
tell application "Mail" to set theMessages to (messages of inbox whose subject is thePrefix)
repeat with oneMessage in theMessages
tell application "Mail" to set theDescription to the content of oneMessage
set {TID, text item delimiters} to {text item delimiters, "reserved for "}
set theContent to text item 2 of theDescription
(*if theContent contains "starting on hole" then
set text item delimiters to ","
else
set text item delimiters to "."
end if*)
if theContent contains "starting on hole" then
set text item delimiters to ", starting"
else
set text item delimiters to "."
end if
set theContent to text item 1 of theContent
set text item delimiters to " on the "
set theDate to text item 1 of theContent
set theCourse to text item 2 of theContent
set text item delimiters to " golf course"
set theSummary to text item 1 of theCourse
set text item delimiters to " at "
set theTime to text item 2 of theContent
set text item delimiters to ":"
set {hr, mn} to text items of theTime
set text item delimiters to TID
set theStartDate to date theDate
tell theStartDate to set {its hours, its minutes} to {hr, mn}
tell application "iCal"
set theCalendar to "Calendar"
tell calendar theCalendar to make new event at end of events with properties {summary:theSummary, description:theDescription, start date:theStartDate}
end tell
tell application "Mail"
set read status of the oneMessage to true
move oneMessage to mailbox mboxArchiveName
end tell
end repeat
hey there, I’ve been trying to wangle applescript above to fit in with an email that I’m sent and wondered if you could add some insight into where I’m going wrong.
I get an email Subject ‘Hotel Pick up’
The body of the email reads:
Submitted values are:
Service Required:
- Hotel Pick up
Contact details:
Name: Tester3
Company name: tester3
Email Address:
Phone number: 346746
Mobile Number: 3467465
Mobile number of person traveling: 456756
Details for pick-up:
Pick-up date: 20/10/2010
Pick-up time: 5:26 pm
Pick-up address:
45674567
Destination address:
45674567
Type of vehicle:
-
Details of return journey:
Return pick-up date: 07/28/2010
Return pick-up time: 5:26 pm
Return pick-up address:
Return destination address:
Further requirements:
Additional Information:
Submitted on 07/28/2010 - 17:46
Submitted by user:
The results of this submission may be viewed at:
Now i’ve managed to get the email to transfer to ical but the time is not being parsed. I’m sure my delimiters are up the spout.
Here is how I’ve changed the script:
tell application "Mail"
set mboxName to "Inbox"
set thePrefix to "Hotel Pick up"
tell application "Mail" to set theMessages to (messages of inbox whose subject is thePrefix)
repeat with oneMessage in theMessages
tell application "Mail" to set theDescription to the content of oneMessage
set {TID, text item delimiters} to {text item delimiters, "Pick-up date: "}
set theContent to text item 2 of theDescription
set theContent to text item 1 of theContent
set text item delimiters to " Pick-up date: "
set theDate to text item 1 of theContent
set text item delimiters to " Pick-up time: "
set theTime to text item 1 of theContent
set text item delimiters to ":"
set {hr, mn} to text items of theTime
set text item delimiters to TID
set theStartDate to date theDate
tell theStartDate to set {its hours, its minutes} to {hr, mn}
tell application "iCal"
set theCalendar to "Work"
tell calendar theCalendar to make new event at end of events with properties {description:theDescription, start date:theStartDate}
end tell
tell application "Mail"
set read status of the oneMessage to true
move oneMessage to mailbox mboxArchiveName
end tell
end repeat