Scripting a copy-paste action

Hi there,

I’m an old Devonthink user but (shame on me) a total beginner in scripting.

As historian, I’m using a complex zettelkasten-like system to manage thousands of notes in Devonthink. Each chunk of text in markdown is pointing by links in several other chunks of text in markdown.

I’m using for this : [Title of the document](devonthink link of the document)
It’s a little bit long to select the file, copy the title, paste the title into [], type (), return to file, copy the devonthink link of the file, go to the second file, paste the devonlink…

I’m searching how to create a script that is able to copy in clipboard this expression (Title of the file+devonthink link) when I’ve selected a file.

Someone to help a poor French historian ?

Merci (thank you)

Benjamin

Hi, try this script. Couldn’t test but should work

tell application id "DNtp"
	try
		set windowClass to class of window 1
		if {viewer window, search window} contains windowClass then
			set currentRecord_s to selection of window 1
		else if windowClass = document window then
			set currentRecord_s to content record of window 1 as list
		end if
		
		set theRecord to item 1 of currentRecord_s
		
		set theName to name of theRecord
		set theRefURL to reference URL of theRecord
		
		set theMarkdownLink to "[" & theName & "](" & theRefURL & ")"
		
		set the clipboard to theMarkdownLink
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell

I wrote something similar for Ulysses with Alfred which lets you search by title and puts a markdown link on the format you describe on the clipboard.

I’ve been thinking of converting / rewriting it for DT (actually it will probably be 99% new code…)… i’ll see if I can find time to tackle it this week.

@pete31 The script is working perfectly well. Thank you so much. very useful.

In case you’re trying to run the script I posted in this thread you’ll find that it doesn’t work in DEVONthink 3.6.

That’s due to DEVONthink’s new handling of “invalide arguments”.

If you want to use the script you’ll have to replace this voluminous block …

set windowClass to class of window 1
if {viewer window, search window} contains windowClass then
	set currentRecord_s to selection of window 1
else if windowClass = document window then
	set currentRecord_s to content record of window 1 as list
end if

… with this neat line …

set currentRecord_s to selected records

… which does what the six lines have done. Wow, that’s great! :smiley: