是的,這是可能的。我曾經用它與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的方式執行此操作,而無需單獨檢查每個郵箱。 (雖然它可能使用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
不過,我的經驗看,如果你有一個複雜的設置,運行這樣的腳本(包括這個腳本)會使郵件的智能(和啞巴)郵箱與其中的郵件的read status
不同步。