Remove unread count from Gmail IMAP

If you’re still using a POP email account, you should have a look at other providers. Gmail recently began offering IMAP service for its clients, and it is a much better way of organizing your email.

IMAP is different from POP email because it keeps all messages and attachments on the central Gmail servers. This means that regardless of how or where you download and view messages – whether on your computer, iPod, iPhone or other device – you see the same inbox, with the same unread/read messages. This is different than POP because POP requires you to download all new messages onto your computer, which makes retrieval from different places awkward.

I use Apple’s for all of my email duties, and its integration with IMAP accounts presents some unique challenges. One of the things it does is create a complete deposit for all the messages ever sent with your account in a special folder. In itself not a bad thing, in fact it can be quite handy, but it means that you now have duplicate copies of most of your messages, and twice as many unread messages.

Until Apple and Google coordinate their efforts and make Gmail as seamless on the Mac as they have with the iPod/iPhone, there are a few things you can do to make the experience easier. One of the ways is to use this hint from It gets rid of the duplicate mailboxes in Gmail. Next, you have to find a way to get rid of the double mail count. To do this, I came up with a simple Applescript that is evaluated whenever there is a new message.

tell application "Mail"
set unreadBox to mailbox "[Gmail]/All Mail" of account "Gmail IMAP"
set unreadCount to unread count of unreadBox
if unreadCount is not 0 then
repeat unreadCount times
set unreadMail to first message of unreadBox whose read status is false
set read status of unreadMail to true
end repeat
end if
end tell

This tells Mail to mark every message in the All Mail folder as read, thereby reducing the number of unread messages to their correct value. Be sure to change the account name to your correct account. To find this out, open Mail’s preferences and use the account nickname you’ve set up.

To use this script in Mail, you’ll need to open Script Editor (/Applications/Applescript/Script Editor) and save this text as a script in some place you’ll remember. Then open Mail’s preferences, and create a new rule that is evaluated at each incoming message. Find the script file, and you should avoid the excess messages.

Update: If you don’t want to write and save the script yourself, you can easily download the script directly.

Tagged with: , , ,
3 comments on “Remove unread count from Gmail IMAP
  1. Thanks for the explanation, this will be really usefull for me. Im still using POP with my Gmail account and hate having to re-read all of my emails when ive already read them on my iPhone and vice versa.

  2. lee says:

    Thank You…!! So Much

    Switched from pop to imap two days ago, and have been so damn annoyed at having to mark everything as “read” twice i was about to switch BACK to pop!
    Your script has worked great, now emails are clean and tidy.

    Thanks a lot my friend..

  3. Dave says:

    Well… genius !! thanks

Leave a Reply

Your email address will not be published. Required fields are marked *