使用AppleScript,是否可以检查未读电子邮件?

时间:2017-07-28 12:58:07

标签: applescript

我刚刚发现AppleScript,我正在学习。我想创建一些可以查看我的电子邮件的内容,看看我是否有新的电子邮件。如果是,我希望它返回一个值(即“邮件”)。如果没有,那么我希望它返回一个不同的值(即“无邮件”)。我的想法是使用Mail应用程序来实现这一目标。

查看“邮件应用程序的字典”(http://www.mugginsoft.com/html/kosmictask/ASDictionaryDocs/Apple/Mail/OS-X-10.7/Mail-5.2/html/),这看起来不太可能,因为您似乎无法检查特别是未读邮件。

1 个答案:

答案 0 :(得分:0)

是的,这是可能的。我曾经和Geektool一起用它来show a list of read messages,我还没有处理过。

在您的情况下,它更容易,因为您不想保留未读消息的列表,但只要在发现任何消息后立即退出。

您正在寻找的旗帜是“阅读状态”。

tell application "Mail"
    if exists (messages of inbox whose read status is false) then
        "Mail"
    else
        "No Mail"
    end if
end tell

请注意,您必须查看特定邮箱;在这种情况下,我正在看inbox。如果您使用规则将邮件预先分发到其他邮箱,我不知道使用AppleScript执行此操作的方法,而不单独检查每个邮箱。 (虽然可以直接在Mail的数据库文件中使用sqlite。)

如果您需要在其他邮箱中查找未读邮件,这也可能有效:

tell application "Mail"
    if exists (messages of inbox whose read status is false) then
        return "Mail"
    else
        repeat with box in mailboxes
            tell box
                if exists (messages whose read status is false) then
                    return "Mail"
                end if
            end tell
        end repeat
    end if
    return "No Mail"
end tell

然而,我的轶事经验是,如果你有一个复杂的设置,运行这样的脚本(包括这个)往往会使Mail的智能(和哑)邮箱与read status的{​​{1}}不同步其中的信息。

相关问题