2011-11-16 5 views
0

メールボックス内のすべてのメールを調べ、件名に "French"という単語が含まれているものを探しますそれらの電子メールの件名をすべてテキストファイルにコピーします。ここで私は残念ながらInbox内のメールの件名をフィルタリングするApplescript

tell application "TextEdit" 
    make new document 
end tell 

tell application "Mail" 
    tell the mailbox "Inbox" of account "[email protected]" 
     set numm to count of messages 
      repeat with kk from 1 to numm 
       set wordsub to subject of the message kk 
       tell application "TextEdit" 
        if "French" is in wordsub then 
         set paragraph kk of front document to wordsub & return 
        end if 
       end tell 
      end repeat 
    end tell 
end tell 

思い付いたものです、私はエラー

"TextEdit got an error: The index of the event is too large to be valid."

を受け続けると私はすでに多くの成功なしでそれを修正しようとしている時間のカップルを費やしてきました。私のコードを見て、何が間違っているのを見てください。

答えて

1

主な問題は、TextEditの段落数と電子メールメッセージの数がお互いに関係がないため、メッセージ数を考慮するとTextEditはそれを理解できません。たとえば、50のメッセージがあるかもしれませんが、TextEditには50個の段落がないため、エラーになります。このように、TextEditには別のカウンタを使用します。

他にも変更を加えました。私はしばしば、あるアプリケーションに別のコードのブロックを伝えることによってエラーが発生するのを見ています。また、 "tell application"ブロック内の唯一のコードは、アプリケーションが処理するために必要なものだけであることにも注意してください。これもエラーを回避します。これらは、プログラミングのときに持つ良い習慣です。

ので...これにも説明のための

set searchWord to "French" 
set emailAddress to "[email protected]" 

tell application "Mail" 
    set theSubjects to subject of messages of mailbox "INBOX" of account emailAddress 
end tell 

set paraCounter to 1 
repeat with i from 1 to count of theSubjects 
    set thisSubject to item i of theSubjects 
    if thisSubject contains searchWord then 
     tell application "TextEdit" 
      set paragraph paraCounter of front document to thisSubject & return 
     end tell 
     set paraCounter to paraCounter + 1 
    end if 
end repeat 
+0

おかげで多くのことを、試してみてください。私はちょうどそれをテストし、それは動作します! – user1227

関連する問題