Insert item link issue

  1. in a markdown doc I created in DT I select a word.
  2. right-click the highlighted word
  3. choose insert > item link…
  4. double-click the doc I want to link to

now, what happens is the highlighted word is deleted. the name of the doc I choose to link to is inserted in square brackets followed by DT item link in round brackets.

I thought it would put the highlighted word in square brackets, omit the linked to doc’s name, and put the DT item link in round brackets. so I expect to get my chosen word as a link anchor, and not the linked to doc’s name (I can get this using wikilcnks, can’t I?).

so am I doing anything wrong?
any suggestions on how to fix this?

I don’t know if this is how it should work but that’s what I’d expect too.

In case it’s no bug here’s a script that saves some steps. Place the cursor behind the word you want to use as link name, insert the link, then select the link and the word and run the script.

tell application id "DNtp"
		set selectedText to selected text of window 1
			set selectedText to selectedText as string
		on error
			display alert "Please select some text." buttons {"Ok"} default button 1 message "" as informational
		end try
		set newLinkName to characters 1 thru ((offset of "[" in selectedText) - 1) in selectedText as string
		set oldLinkName to characters ((offset of "[" in selectedText) + 1) thru ((offset of "](" in selectedText) - 1) in selectedText as string
		set newLink to characters ((length of newLinkName) + 1) thru -1 in my replace_String(selectedText, oldLinkName, newLinkName) as string
		set selected text of window 1 to newLink
	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

on replace_String(theText, oldString, newString)
	local ASTID, theText, oldString, newString, lst
	set ASTID to AppleScript's text item delimiters
		considering case
			set AppleScript's text item delimiters to oldString
			set lst to every text item of theText
			set AppleScript's text item delimiters to newString
			set theText to lst as string
		end considering
		set AppleScript's text item delimiters to ASTID
		return theText
	on error eMsg number eNum
		set AppleScript's text item delimiters to ASTID
		error "Can't replaceString: " & eMsg number eNum
	end try
end replace_String
1 Like

Hey @pete31, Thank you for your response.
Unfortunately I know nothing about AppleScript, so I’m not sure how to use your solution.
Still I’d like very much to get a certified answer whether or not this is a bug or misunderstanding on my behalf.

Yes, you are misunderstanding the feature.

You are inserting an item link, i.e., you are adding a link to the file. In the case of selected text, it replaces it with the inserted link.

Link to from the contextual menu is not available in Markdown files, though it is supported in rich text. Development would have to assess the feasibility of supporting it in Markdown.

  • Open Script

  • Paste the script

  • Save it to

    • /Users/USERNAME/Library/Application Scripts/com.devon-technologies.think3/Toolbar/ if you want to use it from the toolbar


    • /Users/USERNAME/Library/Application Scripts/com.devon-technologies.think3/Menu/ if you want to use it from the scripts menu
  • If you choose to use the toolbar

    • Restart DEVONthink
    • Right click on toolbar
    • Choose “Customize Toolbar”
    • Find the script and drag it to the toolbar

Before you do this try the script in Script Editor to see if it’s something for you.


Thank you, @BLUEFROG for clearing that up

Thank you, @pete31 for this elaborate explanation. I will give it a try.

No problem.

@pete31, it works like a charm! Thank again

Great to hear that

Hey @pete31,
So it did worked like a charm…
and then it stoped :confused:
But also other scripts stoped working correctly.
I even reinstalled devonthink trying to sort the problem - with no luck.
Do you have any idea?

No idea why scripts stop working. Maybe @BLUEFROG can help?

  • Have you made any changes to the system, like updating the operating system?
  • Does the problen persist after rebooting the machine?

Thank you, @pete31

Yes, @BLUEFROG, I erased the disk and clean installed latest Mac OS (about a week ago).
The problem persist after rebooting.

By the way @pete31, when using your script I get this

You didn’t use an inserted link.

I feel so stupid.
Thank you, of course it works perfect now.