Вам нужно решить 2 задачи: 1) извлечь / проверить данные из текста электронной почты 2) создать новое событие в iCal из данных.
Вы уже выполнили вторую часть: создали событие календаря из данных.
Безусловно, самая сложная часть - это извлечь данные из неструктурированного свободного текста (даже полезного, потому что это форматированный текст!) В теле письма.Это роль 1-й подпрограммы в скрипте ниже.
Он использует разделители текстовых элементов Applescript с ":", и я добавляю другие разделители, потому что содержимое письма не текст, а форматированный текст(включая возврат, перевод строки, ...).Я предполагаю, что за строкой текста с «Имя» должны следовать «:» и имя (одно или несколько слов).То же самое для комнаты и даты.Что касается времени начала / окончания, строка должна содержать «Начало» / «Конец», и после «:» я предполагаю, что время установлено в часах: минутах.
Например, нижняя часть тела действительна:
Name: Stackoverflow
Date: 21/12/18
Start Time: 13:30
End Time: 15:45
Room Number: Board Room
Примечание: строки могут быть в любом порядке.здесь номер комнаты - последняя строка.
В приведенном ниже сценарии я предполагаю, что используемое электронное письмо является первым электронным письмом, выбранным в Почте.Вы можете настроить эту часть.
property myCalendar : "Local"
tell application "Mail" -- extract the selected email and get its content as list of paragraphs
set mySelection to selection
set myMail to first item of mySelection
set myLines to every paragraph of (content of myMail)
end tell
set myEvent to ExtractfromRichText(myLines) -- parse the paragraphs to make a record {EName, ERoom,EStart,EEnd}
if EName of myEvent is not "" then CreateNewEvent(myCalendar, myEvent)
-- end of main
-- *******************
on ExtractfromRichText(LocalLines) -- convert the rich text with fixed format into a data set
set AppleScript's text item delimiters to {":", return & linefeed, return, linefeed} -- to remove all rich text end lines
repeat with aLine in LocalLines
try
if text item 1 of aLine contains "Name" then set LName to text item 2 of aLine
if text item 1 of aLine contains "Date" then set LDate to date (text item 2 of aLine)
if text item 1 of aLine contains "Room" then set LRoom to text item 2 of aLine
if text item 1 of aLine contains "Start" then
copy LDate to LStart
set hours of LStart to ((text item 2 of aLine) as integer)
set minutes of LStart to (word 1 of (text item 3 of aLine) as integer)
end if
if text item 1 of aLine contains "End" then
set LEnd to LDate
set hours of LEnd to ((text item 2 of aLine) as integer)
set minutes of LEnd to (word 1 of (text item 3 of aLine) as integer)
end if
on error -- unexpected format
log "error"
return {EName:""} -- not proper email format for calendar events. return empty name
end try
end repeat
return {EName:LName, ERoom:LRoom, EStart:LStart, EEnd:LEnd}
end ExtractfromRichText
-- *******************
on CreateNewEvent(LCalendar, LEvent)
tell application "Calendar" to tell calendar LCalendar
make new event at end with properties {summary:EName of LEvent, location:ERoom of LEvent, start date:EStart of LEvent, end date:EEnd of LEvent}
end tell
end CreateNewEvent