Getting a selection in Mail

:? I want to get a selected bit of text in a message and act upon it. I found a public domain script and tried to use it but it fails. I tried:

tell application “Mail”
set selContent to the selection
display dialog selContent
end tell

and I get a message that “Mail got an error. Can’t make (message # of InBox) into a string”

Apparently the script I stole the code from used to work. (It was a ROT13 script)

Is there another way to get the selection?
Thanks!

In the “Mail” app property selection is to get the selected messages, and not to get the selected text of the message (and is a list). One solution to get the selected text is this:


set the clipboard to ""
set theContent to ""
tell application "Mail" to activate
tell application "System Events" to keystroke "c" using {command down}

repeat while theContent = ""
	set theContent to (the clipboard as string)
	delay 0.1
end repeat

tell me to activate
display dialog theContent

To get entire text of the 1st selected message in the selection list:


tell application "Mail"
	activate
	set oneMessage to item 1 of (get selection)
	set theContent to content of oneMessage
end tell

tell me to activate
display dialog theContent