New Mail Dialogue

I have a little script that brings up a dialogue which tells me I have new mail. However, I can’t seem to set the rule up right to launch within Mail.app when I have new mail. Here’s the script:

How do I set it up in mail.app and does the script syntax have to be different for this to work?

This might work:

on perform_mail_action(info)
	tell application "Finder"
		activate
		display dialog "You Have New Mail." buttons {"OK"} default button "OK" with icon note giving up after 5
	end tell
end perform_mail_action

Set up a rule whose criteria is “Every Message” and then tell it to run the script.

If you want the dialog to pop up in the app that is currently being used, eliminating the need to bring Finder to the front, this might work:

on perform_mail_action(info)
	tell application (path to frontmost application as text)
		display dialog "You Have New Mail." buttons {"OK"} default button "OK" with icon note giving up after 5
	end tell
end perform_mail_action

– Rob

Rob,
Thanks for the code. The second one works for me.