2017-07-28 66 views
0

我剛剛發現了AppleScript,而且我正在學習。我想創建一些能檢查我的電子郵件,看看我是否有新電子郵件。如果是,我希望它返回一個值(即「郵件」)。如果不是,那麼我希望它返回一個不同的值(即「無郵件」)。我的想法是使用郵件應用程序來實現這一點。使用AppleScript,是否可以檢查未讀電子郵件?

查看郵件應用程序的字典(http://www.mugginsoft.com/html/kosmictask/ASDictionaryDocs/Apple/Mail/OS-X-10.7/Mail-5.2/html/),這看起來不太可能,因爲它似乎沒有特別檢查未讀郵件。

回答

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的方式執行此操作,而無需單獨檢查每個郵箱。 (雖然它可能使用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不同步。

相關問題