【问题标题】:Using AppleScript, is it possible to check for unread emails?使用 AppleScript,是否可以检查未读电子邮件?
【发布时间】:2017-07-29 00:53:43
【问题描述】:

我刚刚了解了 AppleScript,并且正在学习中。我想创建一些东西来检查我的电子邮件,看看我是否有新的电子邮件。如果是,我希望它返回一个值(即“邮件”)。如果不是,那么我希望它返回一个不同的值(即“无邮件”)。我的想法是使用 Mail 应用程序来实现这一点。

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

【问题讨论】:

    标签: applescript


    【解决方案1】:

    是的,这是可能的。我以前用 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 不同步他们。

    【讨论】:

      猜你喜欢
      • 2020-11-18
      • 1970-01-01
      • 2011-04-10
      • 1970-01-01
      • 2014-09-25
      • 2013-09-13
      • 2023-03-20
      • 2015-11-07
      相关资源
      最近更新 更多