Mail.app: Next Unread Message

(Using Mail.app v2.*)

tell application "Mail"
	activate
	
	set messageList to {}
	get message viewer 1's selected mailboxes
	repeat with thisBox in result
		set messageList to messageList & (messages of thisBox whose read status is false)
	end repeat
	
	try
		set message viewer 1's selected messages to {(messageList's last item)}
	on error
		beep
	end try
end tell

You may want/need to change last item to first item (depending on how you view and sort your messages).

Model: Mac mini
AppleScript: 1.10.7
Browser: Safari 2.0.4 (419.3)
Operating System: Mac OS X (10.4)

Nice. In the following I’ve simplified it without the repeat loop:

tell application "Mail" to try
	tell message viewer 1 to set selected messages to {first message of beginning of (get selected mailboxes) whose read status is false}
	activate
on error
	beep
end try

Even better Qwerty. :cool:

I had been using the repeat loop for something else before I went with the above. (I’m not familiar with Mail’s dictionary.)

I realize that this is a very old post. On the chance anyone is still watching this, I have a question.

On 10.5.7, in Mail 3.6, I noticed that this script does not move from mailbox to mailbox (it does seem to select the first unread message in the selected mailbox).

Any one have any idea on how to update the script to select the next unread message, regardless of which mailbox it is in?