【问题标题】:Getting at a Message from a Mail Rule in Applescript从 Applescript 中的邮件规则中获取消息
【发布时间】:2012-02-10 21:06:13
【问题描述】:

作为学习 Applescipt 的借口,我编写了一个脚本以附加到邮件规则以过滤消息。我四处寻找并整理了这么多代码:

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

我原以为规则只会传递一条消息,但你永远不知道,所以重复是有意义的。我认为“选择”是指向 theSelectedMessages 中的项目的指针。看起来很奇怪的是“将 theMessage 设置为 theMessages 的第 1 项”。我原以为您会编写“将消息设置为选择”的代码。我想获取消息的正文“内容”来测试某些单词。

感谢您的帮助, 生硬

【问题讨论】:

    标签: email applescript


    【解决方案1】:

    /Library/Scripts/Mail Scripts/Rule Actions/Sample Rule Action Script.scpt 中有一个示例规则脚本。您将需要使用 Mail 脚本字典中设置的处理程序声明,即

    on perform mail action with messages theMessages for rule theRule
    

    【讨论】:

    • 我没有找到你引用的脚本。我打开了 Finder,然后打开了 GO Library。我没有看到名为 Scripts 的目录。我正在运行 OS X 10.7.3。我最终通过在 Applescript Editor 中从 Template/Mail/Mail Rule Action.scptd 执行 File/New 找到了一个示例
    • 有 3 个库文件夹,您可能正在查看用户文件夹中的那个。我引用的那个位于启动磁盘的根级别,可供所有用户使用。不过,该脚本看起来非常接近 Library 文件夹中的内容。
    • 你说得对,它就在那里。我只需要弄清楚如何到达它。
    • 在所有 3 个库文件夹中也没有适合我的示例脚本。不幸的是,这段代码在 macOS 10.13 中似乎不再有效。收到错误消息„given“, „into“, „with“, „without“ or other parameter expected but found identifier.,其中选择了“邮件”一词。
    【解决方案2】:

    当添加另一行代码时,user866649 的答案仅对我有效(macOS 10.13):using terms from application "Mail"

    sn -p 之后显示所有触发脚本的消息的发件人姓名:

    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
    

    【讨论】:

      猜你喜欢
      • 2014-11-15
      • 1970-01-01
      • 1970-01-01
      • 2015-06-05
      • 2018-11-06
      • 2023-04-03
      • 2014-11-15
      • 2012-06-06
      • 2018-08-13
      相关资源
      最近更新 更多