Append selected PDF text to existing MD note?

Hi, I’m a fairly new user of DT3 (many thumbs up!) for a large qualitative research project. I’m convinced there must be a way to do this already but I have searched through docs & discussions & scripts and I can’t find it the answer.

I want to: 1) select text inside a document in DT3, usually PDF; 2) append the text to the bottom of one of several existing markdown notes; 3) with a titled link back to the document (ideally to the selection but not a big deal).

The use case is basically stripped down Nvivo: I am reading through large numbers of PDF transcripts in DT3 and want to quickly select text and send it to one of several thematic notes that aggregate excerpts related to specific themes. If the answer is scripts, I’d be happy to set up a separate script for each thematic note, or otherwise invoke the ‘recent destinations’ pop-up.

I know this is possible manually via copy & paste with source link, I just want to speed it up and avoid window switching by automatically appending. I’m sure I’m missing something obvious, any help is greatly appreciated! (I did find some relevant discussions of scripts but from other apps and also from DT2).

Thanks a lot,
Lucas

Welcome @dlgraves

  • Edit > Copy with Source Link and pasting into the target document is the recommended method. There is no script built-in for this. However, it may be possible to write one, if you’re so inclined.

  • You could potentially use the Services > Take Rich Note and Append Rich Note. The Append command will continue using the last note created via the Take command. This would be useful if you’re working one theme at a time.

  • Haha - Criss beat me to the next suggestion. Indeed the annotation file is also possible. However, a document only has one annotation file, so the aggregated data would be in one document, not over several.

One possibility might be to use the Annotations & Reminder inspector and the Markdown template. Afterwards quotes and back links can be inserted via its popup menu.

Thank you! One quick follow-up question:

If I did try scripts customised for each aggregated theme document, I assume AppleScript would be the way to go? (If anyone has a good idea for an existing script to try to tweak, that would be a huge help.)

The Append Rich Note command is intriguing but if there’s no way to ever aim it at a different note than the last one created, it wouldn’t work.

Thanks a lot
Lucas

You’re welcome :slight_smile:

Generally speaking, AppleScript is most commonly used, including by us internally.

Here’s a simple example targeting one theme. …

tell application id "DNtp"
	try
		set theText to (selected text of think window 1)
		set kayakDoc to (get record with uuid "x-devonthink-item://7D62A822-C455-4E91-84D6-3BE6FDFB1D53")
		tell kayakDoc
			set plain text to (its plain text & linefeed & linefeed & theText)
		end tell
	on error msg
		display alert msg
	end try
end tell

You get the item link via Edit > Copy Item Link.

Selected text in a document. Note: The Kayaking Notes document is frontmost only for this illustration. For the script, the document you’re copying from should be the frontmost.

yields…

Amazing!!! Thanks a lot, that’s tremendously helpful, it would’ve taken me hours to get there.

You’re very welcome :smiling_face:

…and here it is with the titled link added after the quoted text. Hallelujah.

**tell** *application* *id* "DNtp"

try
set theText to (selected text of think window 1)
set theName to name of content record
set theLink to reference URL of content record
set theSource to “[” & theName & “]” & “(” & theLink & “)”
set kayakDoc to (get record with uuid “x-devonthink-item://whatever”)
tell kayakDoc
set plain text to (its plain text & linefeed & theText & linefeed & linefeed & theSource)
end tell
on error msg
display alert msg
end try
end tell

Please include your code in three backticks like so:
```
code goes here
```
That enables highlighting and copy/paste.

Very good :slight_smile: I’m glad it made sense to you.