# DEVONthink script

**URL:** <https://discourse.hookproductivity.com/t/devonthink-script/1242>\
**Category:** Discussion & Help\
**Created:** [February 13, 2020, 9:50pm UTC](https://discourse.hookproductivity.com/t/devonthink-script/1242 "2020-02-13T21:50:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![canadasteven](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/c/9dc877/32.png) [@canadasteven](https://discourse.hookproductivity.com/u/canadasteven)\
**Post date:** [February 13, 2020, 9:50pm UTC](https://discourse.hookproductivity.com/t/devonthink-script/1242/1 "2020-02-13T21:50:23Z")

</div>

In order for DEVONthink to display clickable links, the new document needs to be markdown  
[link to devonthink forum](https://discourse.devontechnologies.com/t/x-callback-url-how-to-create-clickable-link-inside-dttg-to-external-app-in-this-case-drafts-on-ipad-iphone/53666)

So I modified the script in Hook to change the type:txt to type:markdown

Question: how can I copy the markdown link within this script (not using the shortcuts), and THEN paste this in the main body of the new document? [I know I can do this manually, but it takes many steps,

1. open hook,
2. then command M which copies the markdown link,
3. then I open hook again, choose new DEVONthink file using my modified script, run it,
4. open the devonthink file and
5. paste in the body

I have also tried to add:  
tell application “System Events” to key code 9 using command down  
which should be paste from clipboard  
[cool list of Mac system events](https://eastmanreference.com/complete-list-of-applescript-key-codes)  
this did not work

---

<div class="post-metadata">

**Author:** ![grahamb](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/grahamb/32/369_2.png) [@grahamb](https://discourse.hookproductivity.com/u/grahamb)\
**Post date:** [February 17, 2020, 3:32am UTC](https://discourse.hookproductivity.com/t/devonthink-script/1242/2 "2020-02-17T03:32:35Z")

</div>

Try this Link to New script:

```auto
tell application id "DNtp"
	set newItem to create record with {name:"$title", type:markdown, plain text:"[$title]($user_link)"}
	set refURL to reference URL of newItem
	set itemPath to path of newItem
end tell
open location refURL
get refURL

```

$title is replaced with the title of the source document when the script runs  
$user\_link is replaced with a link to the source document.

so `[$title]($user_link)` will be transformed into a markdown link to the source document. E.g. `[DEVONthink script - Discussion & Help - Hook Productivity Forum](https://discourse.hookproductivity.com/t/devonthink-script/1242)`

You can specify the plain text contents of a new record created with AppleScript, so  
`set newItem to create record with {name:"$title", type:markdown, plain text:"[$title]($user_link)"}`  
will create a new record with a markdown link to the source document, which, if I understand correctly, is what you’re trying to do.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![lsievert](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/lsievert/32/1390_2.png) [@lsievert](https://discourse.hookproductivity.com/u/lsievert)\
**Post date:** [May 5, 2021, 5:26pm UTC](https://discourse.hookproductivity.com/t/devonthink-script/1242/3 "2021-05-05T17:26:39Z")

</div>

Thank you, this was just what I needed, only a year later LOL.
