Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

You can obtain the number of unread items with the following AppleScript:

tell application "Mail" to get the count of messages of mailbox "INBOX" of account "Me"

As you mentioned you could write a menu bar item, you could use this AppleScript for it.

Alternatively, you can do this with Mail Unread Menu.
However, I'm not sure if it works with Mavericks.

share|improve this answer
1  
Your script shows the number of messages in inbox not from the folder specified in Mail.app settings. –  Debilski Jun 15 at 13:36
    
@Debilski Yes, but the script can be modified—change mailbox "INBOX" to whatever you desire. –  grgarside Jun 15 at 13:37
1  
Does not work for smart mailboxes or at least I did not have any luck with it. –  Debilski Jun 15 at 13:39

Try this:

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
share|improve this answer
    
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. –  Debilski Jun 18 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-qa Jun 18 at 12:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.