如何使用applescript打开电子邮件? [英] How to open an email message using applescript?
问题描述
我正在写一个小苹果脚本,它检索查看器中的所有未读"消息并循环它们.
I am writing a small applescript which retrieves all "unread" messages in the viewer and loops them.
我有两个目标要完成:
我需要获取每封邮件的主题并执行正则表达式以查看它是否适合第 2 步(例如:获取主题为 {.*} 的电子邮件)
I need to get the subject of each message and perform a regular expression to see if it's suitable for step 2 (ex: get emails with subject {.*})
我需要在单独的窗口中打开每条消息,4 秒后,我需要关闭该窗口并继续处理下一条消息
I need to open each message on a separate window and after 4 seconds, I need to close that window and proceed with the next message
你知道怎么做这些吗?
提前致谢.
推荐答案
以下 applescript 对我有用,但我不确定如何进行正则表达式匹配.您可以将 unix 'grep' 函数与 applescript 的 'do shell script
' 命令一起使用,但我不是如何正确使用 grep 的专家.我会把这个留给别人来回答.
The following applescript works for me, but I'm not sure how to do the regex matching. You can use the unix 'grep' function with applescript's 'do shell script
' command, but I'm no expert in how to use grep properly. I'll leave that for someone else to answer.
on run
tell application "Mail"
set myInbox to mailbox "INBOX" of account 1
set myMessages to every message of myInbox
repeat with theMessage in myMessages
if read status of theMessage is false then
if my subjectIsInteresting(subject of theMessage) then
open theMessage
delay 4
close window 1
end if
end if
end repeat
end tell
end run
on subjectIsInteresting(subject)
-- do some regex magic here
return true -- for now
end subjectIsInteresting
这篇关于如何使用applescript打开电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!