# "selected text" and RTF files

**URL:** <https://discourse.devontechnologies.com/t/selected-text-and-rtf-files/17702>\
**Category:** Automation\
**Created:** [August 25, 2014, 10:57am UTC](https://discourse.devontechnologies.com/t/selected-text-and-rtf-files/17702 "2014-08-25T10:57:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![brookter](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/brookter/32/4458_2.png) [@brookter](https://discourse.devontechnologies.com/u/brookter)\
**Post date:** [August 25, 2014, 10:57am UTC](https://discourse.devontechnologies.com/t/selected-text-and-rtf-files/17702/1 "2014-08-25T10:57:18Z")

</div>

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:

```auto
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](https://discourse.devontechnologies.com/t/make-an-annotation-with-links-notes-tags-v2/17221/1)] 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]

---

<div class="post-metadata">

**Author:** ![korm](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/k/e0b2c6/32.png) [@korm](https://discourse.devontechnologies.com/u/korm)\
**Post date:** [August 25, 2014, 12:48pm UTC](https://discourse.devontechnologies.com/t/selected-text-and-rtf-files/17702/2 "2014-08-25T12:48:12Z")

</div>

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.

> [@brookter](#):
>
> differentiate ‘citation’ notes (with selected text) and ordinary notes (without selected text).

Not sure what that means 😕

---

<div class="post-metadata">

**Author:** ![brookter](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/brookter/32/4458_2.png) [@brookter](https://discourse.devontechnologies.com/u/brookter)\
**Post date:** [August 25, 2014, 2:18pm UTC](https://discourse.devontechnologies.com/t/selected-text-and-rtf-files/17702/3 "2014-08-25T14:18:08Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![system](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/2X/4/4e6ff70c96be2eb307a274d890bba8d71ba671b3.png) [@system](https://discourse.devontechnologies.com/u/system)\
**Post date:** [January 21, 2022, 11:22am UTC](https://discourse.devontechnologies.com/t/selected-text-and-rtf-files/17702/4 "2022-01-21T11:22:15Z")

</div>


