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