2012-02-11 86 views
0

我寫了一個由郵件規則調用的腳本。我希望腳本在特定條件下將郵件移動到垃圾箱。它沒有工作,所以我已經評論了測試,但它仍然無法正常工作。我從一個在線教程中獲得了代碼。該教程將消息移至「歸檔」。當我將這個調用替換爲垃圾時,該規則本身起作用。下面是我測試:使用AppleScript將郵件移動到垃圾箱

using terms from application "Mail" 
on perform mail action with messages these_messages for rule this_rule 
    tell application "Mail" 
     set the message_count to the count of these_messages 
     repeat with i from 1 to the message_count 
      set this_message to item i of these_messages 

      --    try 
      --     set this_content to (every character of content of this_message) as Unicode text 
      --     if this_content is in {"", "?"} then error 
      -- if "bowles" is not in this_content and "patton" is not in this_content then 
      set mailbox of this_message to mailbox "Trash" 
      -- end if 
      --    on error error_message 
      --     set this_content to "NO CONTENT" 
      --    end try 
     end repeat 
    end tell 
end perform mail action with messages 

使用最終條款從

聲明的問題是:設定的this_message郵箱郵箱「廢紙簍」

活動代碼的其餘部分是從的AppleScript編輯器模板。

感謝, 柯特

附:是否有任何書籍處理Apple Mail和MailScript?

+0

你可以嘗試簡單的'移動this_message到郵箱「廢紙簍」' - 但顯然別人也有今天郵寄腳本問題:AppleScript的移動郵件後,中止執行(HTTP://計算器.com/questions/9243825) – Flambino 2012-02-12 00:58:57

回答

2

在問這裏之前,我應該做一個更廣泛的Web搜索。希望這個答案對別人有用。我添加了下面的第一行,並從上面的代碼修改了第二行。

 set theAccount to account of mailbox of this_message 
     set mailbox of this_message to mailbox "Trash" of theAccount 
3

而不是試圖將消息「移動」到垃圾箱,您應該只說 delete this_message。然後

Mail.app會根據您的帳戶設置進行(Mail偏好>帳戶>(帳戶)>郵箱行爲>垃圾)和移動郵件到其帳戶的垃圾郵箱或其他根據您的設置立即刪除它。

+0

我已經解決了我自己的問題。你的方法也可能工作 – curt 2012-02-13 21:05:00

相關問題