Integrate Microsoft Word with DEVONthink

As you may have noticed, DEVONthink links are not properly recognized by Microsoft Word.

First of all, when you have one of them (e.g. the “x-devonthink-item://14AE6E1A-DB3E-429B-8A46-4E1C3174A6F2?page=23″) in the clipboard by using the “Copy Page Link” DEVONthink command and paste it to a Word document, you do not get a proper hyperlink but you just see the raw URL. Moreover, when you try to create a Word hyperlink using the normal procedure, (Insert -> Hyperlink… or Command + K) the DEVONthink URL is changed to a degree that cannot be recognized and used by Word. Specifically, after inserting it in the “Link to:” field of the “Insert Hyperlink” Word window

 

it is converted to “file://localhost/x-devonthink-item/::14AE6E1A-DB3E-429B-8A46-4E1C3174A6F2%3Fpage=23″.

Fortunately the changes are not so destructive and the link can become functional using… what else, an AppleScript!

The only requirement for the proper execution of the script is to have either the cursor inside the hyperlink or the hyperlink should be selected with or without any of its adjacent text. If more than one hyperlinks are in the selected text then the first link will be activated by the AppleScript.

The AppleScript code for activating a link in Word is the following:

Click here to open the source code in AppleScript Editor

Now that we can use DEVONthink links in Word it is time to automate the creation of Word hyperlinks! The new hyperlink will have as destination the selected item in DEVONthink and it is created at the cursor position in the front Word document. The display text of the link follows the template: “(Name of DEVONthink record)” or “(Name of PDF file: Page Number)”.

The AppleScript code which creates Word links to a DEVONthink record is the following:

Click here to open the source code in AppleScript Editor

2 Responses to “Integrate Microsoft Word with DEVONthink”

  1. dani firman says:

    hello john :)

    it’s always a great journey every time i visit your blog, your tutorial was very specific and the roadmap also help me to understand “the big picture” clearly. Ok recently i just try the apple script for integrating word and DEVONthink, but honestly i didn’t have any experience or knowledge how to use these script. I already try to run the apple script editor, then paste your script, hit the run button, but it wasn’t succeed yet. Could you explain more “step by step for dummies” how to use these script ? Thank you for your time.

    • Thanks for the comment Dani!

      The use case for the first AppleScript is:

      1) Copy item link from DEVONthink (Edit > Copy Item Link or shift-command-C)
      2) In Word, select text and use Insert > Hyperlink. For “Link To” paste the DEVONthink item link that’s on the clipboard
      3) Place the cursor in the link field or next to it.
      4) Run the script and the DEVONthink item will open

      Source:http://forum.devontechnologies.com/viewtopic.php?f=20&t=15320 – Thanks Korm!

      Before executing the second AppleScript you should have selected only one item in DEVONthink.

Leave a Reply