how to move to top of a mailbox in Mail.app

I wanted to write a script to select the first message in the current mailbox.
so i wrote following script

tell application “Mail”
set curBox to item 1 of selected mailboxes
set msgs to messages of curBox
set selected messages to {item 1 of msgs}
end tell

it gave me an error on the second line “Mail got an error: Can’t get selected mailboxes.”

how can i get this to work?

Hi,

the reference is missing, selected mailboxes and selected messages are properties of message viewer


tell application "Mail"
	tell message viewer 1
		set curBox to item 1 of (get selected mailboxes)
		set msgs to messages of curBox
		set selected messages to {item 1 of msgs}
	end tell
end tell