簡體   English   中英

如何在 Apple Mail Rule 上觸發 AppleScript?

[英]How to trigger AppleScript on Apple Mail Rule?

在 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

蘋果郵件規則

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. Can't get «class mssg» "Incoming POP Messages" of «class mact» id "LONG-ID". Invalid index. 在這種情況下,您可能會發現有關此問題答案的評論很有用。

總結是,為了從 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM