10

I have seen a few scripts for showing sender and subjects of unread email from your Gmail account. But there isn't a script that extract the same information from the Mail.app. So I've put together script that will do the following:

  1. If Mail is open, and there isn't any unread messages, it will show nothing, as to not be obstructive.
  2. If Mail is open, and there is some unread message, it will show all the unread messages in the format of "Sender: Subject"
  3. If Mail is not open, it will show "Mail not open", to remind you why you might not see any unread message. (If this is not needed, simply remove the 2nd and 3rd lines from the bottom of the script.

Anyhow, here's the script:

tell application "System Events"  
    set processList to (name of every process)  
end tell  
if processList contains "Mail" then  
    tell application "Mail"  
        if (unread count of inbox) > 0 then  
            set messageList to (messages of inbox) whose read status is false  
            set output to ""  
            repeat with itemNum from 1 to (unread count of inbox)  
                set output to output & (extract name from sender of item itemNum of messageList) & ": " & subject of item itemNum of messageList & return  
            end repeat  
        end if  
    end tell  
else  
    set output to "Mail not open :("  
end if  

Save the script somewhere, and create a Shell geeklet with something like: osascript ~/Documents/Scripts/UnreadMessages.scpt

Feel free to give suggestions and recommendations :)

Geeklet files to download

Comments

User Avatar
gradientShift 1103 days ago
This is perfect as I have all my POP & IMAP mail accounts synced to mail.

Thank you very much for this script and it works beautifully.
User Avatar
goldkehlchen 1103 days ago
hi bearbo,

great thing! do you think i could use it also with thunderbird Mail?

What would I have to change in the script?
User Avatar
bearbo 1103 days ago
I don't think so, as Thunderbird Mail doesn't seem to support AppleScript. I could be wrong though. If you know where to find the Thunderbird's dictionary, I'd be happy to modify my script to *try* to work with it.
User Avatar
pizza918 1093 days ago
When I do it, it works fine and says mail not open, but when it opens i get a red light and it stops working. is there anything i can do to fix this?
User Avatar
subhash428 1079 days ago
I directly downloaded the script and saved anywhere in my mac. and created the gooklet shell and put " osascript ~/Documents/Scripts/UnreadMessages.scpt " as u saying above. but it is not working. what happedned???
User Avatar
thediehl 977 days ago
I really like this, have seen a few approaches to this, but this is the most direct. I had a limited space, and so I modified this so it would only show the first two.



tell application "System Events"

set processList to (name of every process)

end tell

if processList contains "Mail" then

tell application "Mail"

if (unread count of inbox) > 2 then

set messageList to (messages of inbox) whose read status is false

set output to ""

repeat with itemNum from 1 to 2

set output to output & (extract name from sender of item itemNum of messageList) & ": " & subject of item itemNum of messageList & return

end repeat

return output & "........................"

else

set messageList to (messages of inbox) whose read status is false

set output to ""

repeat with itemNum from 1 to 2

set output to output & (extract name from sender of item itemNum of messageList) & ": " & subject of item itemNum of messageList & return

end repeat

end if

end tell

else

set output to ""

end if
User Avatar
thacche 943 days ago
UnreadMessages.scpt doesn't work for me. I have 4 new messages in my inbox and the script only shows one of them.
User Avatar
Tbo-art 871 days ago
Could you make this for Sparrow?
User Avatar
SomaKhaos 483 days ago
Doesn't work for me. Shows absolutely nothing :(
User Avatar
kankei71 456 days ago
Working fine. Very nice script!

Log in to comment or register here.