Selected Text of webView

I am trying to get the selected or highlighted text in a web view in my project.


set richText to view "RTE" of window "Edit"
		
set mainFrame to (call method "mainFrame" of richText)
set dom to (call method "DOMDocument" of mainFrame)
set selText to (call method "selectedDOMRange" of dom)

but I get “The variable selText is not set”. I am missing a step somewhere, but I am not sure where.

-sD-
Dr. Scotty Delicious, Scientist.

Hi Scotty,

selectedDOMRange is a method of WebView … try this …

set selText to (call method "toString" of (call method "selectedDOMRange" of (view "RTE" of window "Edit")))

for the selection as string

or

set selText to (call method "markupString" of (call method "selectedDOMRange" of (view "RTE" of window "Edit")))

for the selection as HTML string

D.

Dominik! I could kiss you!
However, I am afraid that may come across as a bit creepy, so will you settle for a long distance, e-High five?

That worked brilliantly.

-sD-
Dr. Scotty Delicious, Scientist.