2011-10-14 12 views
0

我正在使用Mail applescript模板(文件>新建模板>郵件>郵件規則Action.scptd)編寫腳本,但它看起來不像模板中的示例正在工作使用蘋果腳本獲取郵件主題

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_subject to (subject of this_message) as Unicode text 
               if this_subject is "" then error 
            on error 
               set this_subject to "NO SUBJECT" 
            end try 
          say this_subject 
          end repeat 
       end tell 
     end perform mail action with messages 
end using terms from 

即使郵件有主題,它也會顯示「無主題」。我使用OS X 10.7.2和Mail 5.1。有什麼建議麼?

+1

看到[這個問題](http://stackoverflow.com/questions/7722381/save-mail-attachment-from-applescript-in-lion)...那裏顯然是在10.7的郵件的Applescript功能的問題。 – eykanal

回答

1

嘗試在set this_subject to (subject of this_message) as Unicode text下添加delay 3。可能是郵件沒有時間處理郵件以獲取主題行,然後再轉到下一個命令。

如果這個工作,你可能不需要3秒鐘。您可以嘗試減少延遲時間。請注意,您可以使用小數,如1.8所示。

0

我有這個在10.8.2(郵件6.2)下工作,如果它有幫助嗎?這是我正在使用的代碼:

using terms from application "Mail" 
    on perform mail action with messages theMessages for rule theRule 
     tell application "Mail" 
      repeat with eachMessage in theMessages 
       try 
        set this_subject to subject of eachMessage 
        if this_subject is "" then error 
       on error 
        set this_subject to "No subject." 
       end try 
       say this_subject 
      end repeat 
     end tell 
    end perform mail action with messages 
end using terms from 

希望有幫助嗎?