View Unread Messages in 1.3.1

I recently switched from Entourage to Mail, iCal and Address Book. One feature that I miss is Entourage’s “custom views”, specifically the ability to view all unread messages regardless of the mailbox they’re in.

I wrote the following script for 1.3.1 to do the same:

tell application "Mail"
	set myMessages to (messages of inbox whose read status is false)
	repeat with currentMailBox in every mailbox
		if (unread count of currentMailBox) > 0 then
			set myMessages to myMessages & (messages of currentMailBox whose read status is false)
		end if
	end repeat
	if (count of myMessages) > 0 then
		set myWindow to first message viewer
		set myMailBoxes to {inbox} & (every mailbox whose unread count is greater than 0)
		set selected mailboxes of myWindow to myMailBoxes
		set visible messages of myWindow to myMessages
	end if
end tell

Originally I had “set myWindow to make new message viewer”. This worked fine when run from Script Editor but failed when run from Mail’s applescript menu. Can’t explain why, but I feel it’s worth mentioning because this forum gave me the working code. Thanks!