2

I'd like to know in a (applescript|bash|python|whatever) script, running on my Yosemite OS X, the sum of unread messages in all accounts of the Apple Mail application - in other words, the same number that appears in Mail's icon badge with the default Apple Mail Preference settings.

Is this scriptable via AppleScript or other means?

1 Answer 1

1
osascript -l JavaScript -e 'Application("Mail").inbox.unreadCount()'

This uses Mail's unified inbox to display the number of unread messages, thus, it's equal to the number on Mail's red icon badge.

2
  • 2
    This is not completely true. Although your AppleScript is correct, the badge icon is not by definition the unread inbox count. In Mail Preferences, you can define which mail-folder represents the badge count. Sep 12, 2015 at 6:17
  • @CousinCocaine that's true, but Longhanks' answer is exactly what I was looking for (sum of unread messages in the main inbox of all configured accounts). I hadn't thought of the possibility to change the badge in Apple's preferences, so my question was actually incorrect. I'm gonna edit it and clarify.
    – Luke404
    Sep 12, 2015 at 16:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .