【问题标题】:How to trigger AppleScript on Apple Mail Rule?如何在 Apple Mail Rule 上触发 AppleScript?
【发布时间】:2020-05-04 14:01:14
【问题描述】:

在 Apple Mail 中,我转到“首选项 > 规则”并制定了触发 AppleScript 的规则(附截图)

我知道它正在触发,因为传入消息的背景变为橙色。

但是,AppleScript 似乎没有触发。我已将其设置为执行一个简单的“显示对话框”,以查看它是否正在触发,但没有任何反应。你能帮我看看我哪里出错了吗?

谢谢!

脚本来自http://preserve.mactech.com/articles/mactech/Vol.21/21.09/ScriptingMail/index.html

这是脚本:

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
        -- Process the current message
        display dialog "did this work?"
    end repeat
end tell end perform_mail_action

【问题讨论】:

    标签: applescript apple-mail


    【解决方案1】:

    MacTech 文章可能已过时。我能找到的有关该主题的 Apple 页面没有提及有关该处理程序的任何内容,带有下划线,仅带有空格。

    前者意味着您的脚本根本不需要处理程序。我已经证实这是真的。以下脚本文件在收到消息时触发,并显示对话框:

    display dialog "Hello without handler"
    

    后一页使用以下格式,我也验证过:

    using terms from application "Mail"
        on perform mail action with messages caughtMessages for rule catchingRule
            display dialog "We got one!"
        end perform mail action with messages
    end using terms from
    

    如果您使用 IMAP,则可以从传入的消息中获取数据。例如:

    using terms from application "Mail"
        on perform mail action with messages caughtMessages for rule catchingRule
            repeat with caughtMessage in caughtMessages
                try
                    set mailSubject to subject of caughtMessage
                    display dialog mailSubject
                on error errorString number errorNumber
                    display dialog errorString
                end try
            end repeat
        end perform mail action with messages
    end using terms from
    

    如果您使用的是 POP,则无法收到传入的消息;你会得到类似Can’t get «class mssg» "Incoming POP Messages" of «class mact» id "LONG-ID". Invalid index. 这样的信息,在这种情况下,你可能会发现the answer to this question 上的 cmets 很有用。

    总结是,为了从 POP 帐户的传入邮件中获取数据,必须首先将邮件移动到收件箱以外的文件夹。让规则将邮件移动到您创建的另一个邮箱中,例如“传入分类”,然后让脚本遍历该邮箱中的所有邮件,而不是遍历提供给处理程序的邮件。例如:

    using terms from application "Mail"
        on perform mail action with messages caughtMessages for rule catchingRule
            --for POP messages, the rule must have already moved it into Incoming Triage
            set caughtMessages to every message of mailbox "Incoming Triage"
            repeat with caughtMessage in caughtMessages
                tell caughtMessage
                    set mailSubject to subject
                end tell
                display dialog mailSubject
                move caughtMessage to mailbox "INBOX" of account 1
            end repeat
        end perform mail action with messages
    end using terms from
    

    【讨论】:

      猜你喜欢
      • 2021-02-04
      • 2017-05-02
      • 2014-12-21
      • 1970-01-01
      • 2011-10-26
      • 2011-10-26
      • 2021-10-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多