作为学习Applescipt的借口,我编写了一个附加到Mail规则的脚本来过滤消息。我匆匆忙忙地把这么多代码放在一起:
on perform_mail_action(theData)
tell application "Mail"
set theSelectedMessages to |SelectedMessages| of theData
set theRule to |Rule| of theData
repeat with a from 1 to count theSelectedMessages
set theMessages to selection
set theMessage to item 1 of theMessages
end repeat
end tell
end perform_mail_action
我原本以为规则只传递一条消息,但你永远不知道重复是有意义的。我假设“选择”是指向选定消息中的项目的指针。看起来很奇怪的是“将消息设置为消息的第1项”。我原本以为你会编码“将theMessage设置为选择”。我想找到消息的正文,“内容”以测试某些单词。
感谢您的帮助, 简略的
答案 0 :(得分:1)
/ Library / Scripts / Mail Scripts / Rule Actions / Sample Rule Action Script.scpt 中有一个示例规则脚本。您将需要使用Mail的脚本字典中设置的处理程序声明,即
on perform mail action with messages theMessages for rule theRule
答案 1 :(得分:1)
user866649s的答案仅在添加另一行代码using terms from application "Mail"
时才对我有效(macOS 10.13)
以下代码段显示了触发脚本的所有邮件的发件人名称:
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
repeat with theMessage in theMessages
display dialog (sender of theMessage as string)
end repeat
end perform mail action with messages
end using terms from