【问题标题】:Applescript that filters the subject line of emails in Inbox过滤收件箱中电子邮件主题行的 Applescript
【发布时间】:2011-11-17 06:39:47
【问题描述】:

我正在尝试编写一个脚本来完成以下工作:它遍历邮箱中的所有电子邮件,找到主题行中包含“French”一词的邮件,然后复制这些邮件的所有主题行文本文件中的电子邮件。这是我想出的

tell application "TextEdit"
    make new document
end tell

tell application "Mail"
    tell the mailbox "Inbox" of account "tigeresque@gmail.com"
        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 出错:事件的索引太大而无效。”

我已经花了几个小时试图修复它,但没有取得多大成功。你能看看我的代码,看看有什么问题吗?

【问题讨论】:

    标签: applescript


    【解决方案1】:

    您的主要问题是 TextEdit 中的段落数和电子邮件消息的数量彼此无关,因此如果您指望消息的数量,那么 TextEdit 将无法理解它。例如,您可能有 50 条消息,但 TextEdit 没有 50 个段落,因此会出错。因此,我们只为 TextEdit 使用单独的计数器。

    我也进行了其他更改。我经常看到一个“告诉应用程序”代码块在另一个代码块中发生错误......所以我将它们分开。另请注意,任何“告诉应用程序”块内的唯一代码只是该应用程序处理所必需的。这也避免了错误。这些都是编程时要养成的好习惯。

    所以试试这个...

    set searchWord to "French"
    set emailAddress to "tigeresque@gmail.com"
    
    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
    

    【讨论】:

    • 非常感谢,也感谢您的解释。我刚刚测试了它,它可以工作!
    猜你喜欢
    • 2016-09-15
    • 1970-01-01
    • 2013-07-11
    • 1970-01-01
    • 2014-04-17
    • 1970-01-01
    • 1970-01-01
    • 2011-06-01
    • 2019-12-02
    相关资源
    最近更新 更多