簡體   English   中英

從 Applescript 中的郵件規則獲取消息

[英]Getting at a Message from a Mail Rule in Applescript

作為學習 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

我原以為這條規則只會傳遞一條消息,但你永遠不知道,所以重復是有意義的。 我認為“選擇”是指向 SelectedMessages 中某個項目的指針。 似乎奇怪的是“將消息設置為消息的第 1 項”。 我原以為你會編碼“將消息設置為選擇”。 我想進入消息的正文“內容”以測試某些單詞。

感謝您的幫助,柯特

/Library/Scripts/Mail Scripts/Rule Actions/Sample Rule Action Script.scpt 中有一個示例規則腳本。 您將需要使用在 Mail 的腳本字典中設置的處理程序聲明,即

on perform mail action with messages theMessages for rule theRule

添加另一行代碼時,user866649s 的答案僅適用於我(macOS 10.13): using terms from application "Mail"

以下代碼段顯示觸發腳本的所有消息的發件人名稱:

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

我也是這個新手...在Catalina中,有一些模板,您可以(在腳本編輯器內 )執行File -> New From Template -> Mail -> Mail Rule Action.scptd該模板具有using terms和一些更多級別選擇每個消息為this_message

另外,(對我來說是新來的),在腳本編輯器中 ,您可以找到帶File Mail Dictionary -> Open Dictionary... ,然后選擇郵件。 在彈出的窗口中,您可以找到每件事(方法,元素,屬性等)的作用。

現在我的問題是如何調試腳本...

暫無
暫無

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

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