RTF-Links from Zotero in Evernote

brain.flush(); > Development > RTF-Links from Zotero in Evernote

In addition to my previous post about connecting Zotero and Evernote I present a solution to create RTF links to Zotero elements in Evernote.

For my workflow it would be great to copy an element in Zotero and paste it as clickable link into Evernote, ideally using the title as text and the Zotero select URI as target. This could only be possible if the function of Zotero that copies text to the clipboard supports formatted (i.e. RTF) content. Usually the clipboard contains several data formats when copying something. If you e.g. copy text from a website containing a link the plain text is stored in the clipboard and additionally there is a version preserving the links, font style and color. Now when you paste the contents e.g. into Microsoft Word, all the formatting will be shown as it was on the website. In notepad only the plain text will be visible. The Zotero (export) translator will always fill the plain text area of the clipboard. Based on my experiments even RTF text with a valid RTF header written to the output won't be recognised as RTF text when pasted into Word or Evernote.

So, what can we do? The first step was to change the output of the Zotero export translator (quick copy) as you can see here. The output now contains at least the Zotero select URI and the title (e.g. <a href="zotero://select/items/0_KJ6MZWKT">CloudML</a>). Then I found the shell command textutil which is able to convert HTML to RTF. You can try the following command in the Terminal which converts an HTML link to RTF and copies the result into the clipboard. Pasting in Word or Evernote will result in a clickable link to Google.com with the text "Test".

echo "<a href=\"http://www.google.com\">Test</a>" | textutil -stdin -stdout -format html -convert rtf | pbcopy

Now that we have a way to get HTML links out of Zotero and found a tool to convert HTML to RTF it's time to put everything together. Automator is a tool in OS X that enables the creation of custom services and workflows. I use it to create a service running a shell command for which a keyboard shortcut can be assigned later on. It's straightforward: Create a service, select "Run Shell Script" and add the command.

Automator in OS X

Automator in OS X

It is very important to set the encoding of the shell environment first because it's not set to UTF-8 as it might be in your Terminal. This is the command I eventually used (Set encoding, use the contents of the clipboard as input for textutil and then save the output in the clipboard):

export LANG=de_DE.UTF-8; pbpaste | textutil -stdin -stdout -format html -convert rtf -inputencoding utf-8 | pbcopy

When you save the workflow it's available in this menu: System Preferences > Keyboard > Shortcuts. In the services category you will find your newly created service and can assign a keyboard shortcut.

Keyboard Shortcuts in OS X

Keyboard Shortcuts in OS X

This is my upgraded workflow with the goal to create clickable links in Evernote pointing to Zotero entries:

  1. Select entries in Zotero, press CMD+Shift+C to copy the HTML links
  2. Press CMD+CTRL+Shift+C to convert the HTML code in the clipboard to RTF
  3. Paste links in Evernote
Evernote with RTF links

Evernote with RTF links

9 thoughts on “RTF-Links from Zotero in Evernote

  • Markus

    Very nice :) is it also possible with Windows? Do you know a solution?

    Reply
    • Flo

      RTF is definitely possible, especially because it's created by Microsoft. :D I think there are programs out there that can modify your clipboard, add RTF content and assign a shortcut, but I don't know any for Windows, sorry!

      Reply

Pingback: Zotero RTF-Link Extended | brain.flush();

  • A.Finn

    Many thanks for your posts on the Zotero Application links!.
    I'd like to point out that they can be used in other applications, beside Evernote.
    I'm using them in Apple Notes (new version).
    For some reason I prefer not to have double quotes in links so I changed a line of your translator to remove them:
    // output += """ + item.title + """; // “ ”
    output += "" + item.title + ""; // “ ”

    do you believe this can cause problems in some situation?

    good work!

    Reply
    • Flo

      Hi! You are welcome! Great to hear that Apple Notes is also compatible with the Zotero application links.

      What did you exactly change in the script? I guess WordPress replaced your "a href" to a HTML link so I cannot read you comment properly. In the given translator there are no double quotes (as you can see in the screenshots) and those written in the script are only part of the HTML syntax. :)

      Reply
      • A.Finn

        Thanks for the kind answer!
        I'm sorry if I didn't make all this clear. Yes, the script lines enclosed were modified by WordPress.
        I'm referring to your third post (not this one but the following): Zotero RTF-Link Extended
        Where in the screenshot the item title is in double quotes, like this:
        "Building ...etc" (Hinchey...etc)
        From your Translator zotselect-link-full.js at line 25 I removed the strings
        ampersand quot;
        to get a link like:
        Building ...etc (Hinchey...etc)
        but I'm not sure if the removed string was there for some some reason.

        Reply
        • Flo

          Oh, I see! No, this was just for "framing" the title and had no further meaning. ;-)

          Reply
  • Erik

    This is all extremely helpful and solved a lot of my problems linking Evernote and Zotero for managing notes, citations and documents.

    I am having trouble getting the workflow to appear on the options for system preferences > keyboard > shortcuts. Is the service I created in automator not saving in the right place? Or could there be a problem with the code I used, which I copied directly from you?

    Reply
    • Flo

      Hey Erik! I love the connection between Evernote and Zotero - good to hear that it's helpful for you too!

      The workflow should appear on the section "services" on the keyboard shortcut preference page. For me it was at the very bottom in the section "General". Did you explicitly saved the workflow in Automator's file menu? This is necessary to have it show up in the preferences.

      There are several places the workflow can be saved as you can read here: https://www.engadget.com/2012/12/17/where-automator-actions-and-workflows-live/

      For me it was located in ~/Library/Services

      Hope that helps and thanks again for your comment! :)

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Archives