"selected text" and RTF files

This is probably a very naive question. My apologies in advance…

I’m trying to test whether a document has any selected text using the following code:

tell application id "DNtp"
	set sourceDocument to (the first item of (selection as list))
	set citedText to the (selected text of think window 1 as string)
	if citedText is "" then set citedText to "no text selected"
	return citedText
end tell

If I run this on a PDF with no text selection, then it works as expected – “no text selected”

But if I run it on an RTF file with no text selection, then it returns the whole text file.

Is that expected behaviour?

If so, how do I test for an empty test selection in an rtf file?

Many thanks

[i][The context: I’m trying to adapt korm’s very useful Keyboard Maestro script for citations [url]Make an Annotation with Links, Notes, Tags v2] to differentiate ‘citation’ notes (with selected text) and ordinary notes (without selected text).

I’ve got everything to work as it should with PDFs, but with RTF source documents, it’s returning the entire text when there’s no text selected and that’s not what I want.][/i]

If “kind is RTF” then you could do a test to compare “citationText” to the “rich text of sourceDoucment” and if the strings are the same, then you probably have not selected any text. A kludgy test, but it is reliable.

Not sure what that means :confused:

Thanks for the quick reply – I wondered if it would be something kludgy like that.

The difference is simply that somethings the notes I take are summaries which are not related to any specific part of the text, so I don’t need the citation element and a simple page reference will do.

Many thanks for the help (and for the numerous scripts you’ve contributed – they’re really helpful).