Best method to point to the message highlighted in Mail

Currently, to identify a selected message in Mail, I use the following method:

tell application "Mail"
	set the_selection to selection
	set the_msg to get item 1 of the_selection
end tell

The result is something like:
message id 66888 of mailbox “INBOX” of account “wladdy.com” of application “Mail”

This allows me to manipulate the message the_msg and works well enough.
However, being a beginner, I feel that I am missing a simpler single-line approach.
For instance, why does this :

tell application "Mail"
	set the_msg to get item 1 of selection
end tell

not work and return the following error message ?
error “Mail got an error: Can’t make item 1 of selection into type specifier.” number -1700 from item 1 of selection to specifier

Any suggestion would help me better understand AppleScript and would be greatly appreciated. Thanks. W.

This works – it’s a matter of timing – what is done first; here I’ve forced the selection to occur first with the parentheses:


tell application "Mail" to set the_msg to item 1 of (get selection)

Thank you Adam! I understand much better now. W.

AppleScript evaluates left to right, so parentheses can be very useful for ordering operations because their contents are evaluated at the deepest level (if you’ve nested them) outward to the main line.