Get selection of NSTextView

Hi Community,
Just as the question poses, I am trying to figure out how to “get” the selection of an NSTextView. I am using the Text View like a Text Field, and I need to know what the user is selecting to use it in the app. Thank you so much!

~Josh Fletcher

If you have a textView called tv, this code will get you the selected text:

set theRange to tv's selectedRanges()'s lastObject()
		log tv's textStorage()'s |string|()'s substringWithRange_(theRange)

Ric

Thank you so much! Exactly what I was looking for!

The second line of the code I showed can be simplified to just " log tv’s |string|()'s substringWithRange_(theRange)" because NSText, which is the superclass of NSTextView, also has a string() method.

Ric