How to get Apple Mail badge (n. of unread messages) from script? 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?
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.