2012-07-18 114 views
0

我看了看,但看不到這個看似簡單的問題(我也是AppleScript的新手)的答案。基本上,我只想創建一個規則並將郵件移動到郵箱「Foo」(我的IMAP帳戶中的郵箱)的腳本。下面是我有:AppleScript將郵件移動到郵箱中的規則郵箱

tell application "Mail" 
set newRule to make new rule at end of rules with properties {name:"Foo Internal", enabled:true} 
tell newRule 
    make new rule condition at end of rule conditions with properties {rule type:any recipient, expression:"[email protected]", qualifier:does contain value} 
    set move message to mailbox "Foo" 
end tell 
end tell 

我已經試過這條線的各種組合...

set move message to mailbox "Foo" 

...包括指定IMAP帳戶,將其設置爲一個變量,依此類推。我不是程序員,但我真的想編寫這些規則,因爲我始終在我的工作中設置規則。任何幫助?

回答

0

你的腳本失敗,因爲兩件事情:

  1. 它省略設置規則爲真,這是需要一個move message行動實際上是「堅持」的should move message財產;
  2. 它沒有正確定義目標郵箱的對象層次結構:您需要同時使用accountapplication上下文,因爲您位於以規則爲目標的tell塊內,而不是郵件。

下面的代碼:

tell application "Mail" 
    set newRule to make new rule at end of rules with properties {name:"Foo Internal", enabled:true, should move message:true} 
    tell newRule 
     make new rule condition at end of rule conditions with properties {rule type:any recipient, expression:"[email protected]", qualifier:does contain value} 
     set move message to (mailbox "Foo" of account "Bar" of application "Mail") 
    end tell 
end tell 

將在郵件工作5.2(股票爲OS X 10.7.4的)。

+0

感謝您的反饋意見。當我在腳本中使用此代碼時,在運行時沒有看到任何錯誤,但規則仍然顯示「未選擇郵箱」。任何想法? – 2012-07-19 03:40:21

+0

我假設你已經確認郵箱和帳戶存在並且拼寫正確嗎?另外,請確保在運行腳本之前刪除任何現有的「Foo內部」規則。最後 - 我應該在以前問過 - 你運行的是什麼版本的Mail和OS X(以上在Mail 5.2/OS X 10.7.4上運行得很好)? – kopischke 2012-07-19 14:35:26

+0

謝謝。是的,我已經三重檢查了郵箱是否存在於正確的帳戶下,並且拼寫是正確的。在重新運行腳本之前,我總是刪除「Foo Internal」規則。我在10.7.4上運行Mail 5.2。任何其他想法?我* * *接近於完成這個腳本,它根據客戶端名稱創建郵箱並設置規則,只需要最後一點工作即可。我正在單獨測試這個規則創建部分,所以沒有其他任何東西與它衝突的機會。我非常感謝你的幫助。 – 2012-07-19 15:57:03