Is there a way to show the exact number of unread mails from the Mail.app icon also in the title bar? Note that this is not the same as showing the number of unread mails in inbox, since I can change the folder to something else like a smart mailbox.

(A script which outputs this number would also be okay; I could write a menu bar item around this myself.)

Update: Alternatively, a script which outputs the number of unread mails for a user-definable smart mailbox is also okay. All example code I’ve seen so far only works for non-smart mailboxes.

set unreadNumber to 0
set i to 1
tell application "Mail"
activate
get message viewer 1's selected mailboxes
repeat with thisBox in result
repeat until ((message number is i) exists) is false
if read status of (message number i of thisBox) is true then set unreadNumber to (unreadNumber + 1)
set i to i + 1
end repeat
end repeat
display dialog "You have " & unreadNumber & " unread messages."
end tell

Not 100% sure what this does but it looks as if it takes quite some time for more than just a few messages. Also, it seems to return the total number of unread messages (?) which is not what I need.
–
DebilskiJun 18 '14 at 11:19

To quote you: "a script which outputs the number of unread mails for a user-definable smart mailbox is also okay." Perhaps you need to make your question clearer.
–
man-qaJun 18 '14 at 12:48