下面是一个使用AppleScript和Shell脚本提取邮件中的文本和日期,并创建日历事件的解决方案:
tell application "Mail"
set theMessage to first message of inbox
set theContent to content of theMessage
set theDate to date received of theMessage
end tell
这段代码将提取收件箱中的第一封邮件的内容和接收日期,并将其存储在变量theContent和theDate中。
#!/bin/bash
# 获取日期和内容
date=$(date -j -f "%a, %d %b %Y %H:%M:%S %z" "$theDate" +"%Y-%m-%dT%H:%M:%S")
content="$theContent"
# 创建日历事件
osascript -e "tell application \"Calendar\" to ¬
tell calendar \"工作\" to ¬
make new event with properties {start date:date, summary:content}"
这段Shell脚本将使用date命令将日期格式转换为日历事件所需的格式,并使用osascript命令使用AppleScript创建一个新的日历事件。
请注意,您需要替换示例代码中的"工作"为您想要创建事件的日历的名称。
#!/bin/bash
# 使用AppleScript提取邮件中的文本和日期
theContent=$(osascript -e 'tell application "Mail" to ¬
set theMessage to first message of inbox ¬
set theContent to content of theMessage')
theDate=$(osascript -e 'tell application "Mail" to ¬
set theMessage to first message of inbox ¬
set theDate to date received of theMessage')
# 使用Shell脚本创建日历事件
date=$(date -j -f "%a, %d %b %Y %H:%M:%S %z" "$theDate" +"%Y-%m-%dT%H:%M:%S")
content="$theContent"
osascript -e "tell application \"Calendar\" to ¬
tell calendar \"工作\" to ¬
make new event with properties {start date:date, summary:content}"
确保将"工作"替换为您想要创建事件的日历的名称。
现在,您可以运行脚本文件extract_and_create_event.sh来提取邮件中的文本和日期,并在指定的日历中创建日历事件。