Markdown external link list of selected items

Hi,

Below is a script based on @Korm’s Make an Index Document (RTF) for a Selection of Documents that creates a new markdown file in the enclosing group with a link list to original(external) URLs of selected items.

Useful for sharing links outside of Devonthink.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

(*
	v1.20131108.korm
	Put an index of the selected documents into a new RTF file in the current group
	
	v1.1 2019-12-28 lavaggio
	Amended to use URL of the item (not reference URL which is a devonthink link) and output to markdown
*)

-- if a label is desired for the index file change this property to an integer from 1 to 7, corresponding to the configured label in DEVONthink
property p_label : 0

-- if you wish to be prompted for the destination for the index file, change this property to true
property ask_destination : false

tell application id "DNtp"
	try
		set theSelection to selection
		if theSelection is {} then error "Select an item, please"
		
		set theContent to ""
		
		repeat with thisItem in theSelection
			
			set thisName to the name of thisItem
			set thisURL to the URL of thisItem
			
			set theContent to theContent & "- [" & thisName & "](" & thisURL & ")" & return
			
		end repeat
		
		set defaultIndex to the name of the current group
		
		set documentName to text returned of (display dialog "Please enter the new file name	" default answer defaultIndex with title "Filename")
		
		set theMD to "# " & documentName & return & return & theContent
		
		if ask_destination then
			create record with {name:documentName, content:theMD, label:p_label, type:markdown} in display group selector
		else
			create record with {name:documentName, content:theMD, label:p_label, type:markdown} in the current group
		end if
		
	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

1 Like

Good work!

However, the URL property points to a URL applied to the file.
From Help > Documentation > Inspectors > Info pane

What you want to get is the reference URL (also called the Item Link when discussing it). So…

set thisURL to the reference URL of thisItem

Cheers!

Thanks!

I meant to reference the URL property – I’m using the script to generate a list of links from a selection of saved bookmarks.

I have a bunch of bookmarks to movies saved in DT and wanted to generate a recommended movie list for a family member.

Ahh…
Perhaps you want to put in a conditional to exclude a document with no URL.
:slight_smile: