check email

Here’s a Mail script that will check your email. If there’s any new mail, it’ll open a new Message Viewer window and select whichever account you tell it to. If not, it does nothing but run your “no new mail” sound in the background, without even switching from the active application. On my computer, I’ve set a hot key of Command-slash for this, so that if my kids are using my computer, I can quickly check for email without interrupting their homework too much.

Replace “your account” with the name of your account (duh), leaving the quote marks as they are.

tell application "Mail"
	set theAccount to account "your account"
	set theMailbox to mailbox "INBOX" of theAccount
	
	set x to unread count of inbox
	check for new mail
	delay 1 -- adjust if necessary
	--a repeat block would be better than a fixed delay, but I don't know how to make one
	set y to unread count of inbox
	
	if y > x then -- new mail for "your account"
		activate
		if not (message viewer 1 exists) then make new message viewer
		repeat until message viewer 1 exists
			delay 0.1
		end repeat
		set selected mailboxes of message viewer 1 to {theMailbox}
	end if
end tell

Simple but useful for me. Hope someone else finds it useful too. Props to Pierre for all your help.

Oh! That is so Cool! Thanks for the Script! :smiley: