Linking from Obsidian to Zotero

Disclaimer: I know nothing about coding, and all I’ve done is arranged some code written by others who know what they’re doing. There were two sources I used (one attributed to Scott Campbell and Avram Lyon, and another by Nathan Schneider), and I’ve credited the authors in the actual body of the code. Also, forgive me if the language sounds like it’s from an “X for Dummies” book; I’m trying to write these as instructions for a confused future me.



Intro:

There’s a lot of information about extracting annotations from Zotero to Obsidian, but it was a little more difficult to find out exactly how I could make a link in Obsidian that would take me to a particular bibliographic entry in Zotero. What one can do, in short, is use Zotero’s “Quick Copy” feature to create a link that you can then paste into Obsidian, and whenever you click it (as long as Zotero is open), the bibliographic entry in Zotero will pop up. That being said, you’ll have to do a little something to make this work, but with a little luck, you can get it to output something like this: [Surname Year - Title](Link to Zotero).

Instructions:

  1. Paste the following code into a text-editor and save this in the “translators” subfolder of the Zotero folder. What this does is creates a file that Zotero’s Quick Copy feature will use to generate the Obsidian-formatted link. I named mine “Obsidian Reference.js”. Note, the text file needs to end in .js. This file name, however, does not affect the name that appears in Zotero. If you want a different name to appear in Zotero, edit the content of the “label” category ("label":"Obsidian Reference",).
{
"translatorID":"76a79119-3a32-453a-a0a9-c92640e3c93b",
"translatorType":2,
"label":"Obsidian Reference",
"creator":"Scott Campbell, Avram Lyon, Nathan Schneider",
"target":"html",
"minVersion":"2.0",
"maxVersion":"",
"priority":200,
"inRepository":false,
"lastUpdated":"2012-07-17 22:27:00"
}

function doExport() {
	var item;
	while(item = Zotero.nextItem()) {
		Zotero.write("[");
		var library_id = item.libraryID ? item.libraryID : 0;
		Zotero.write(item.creators[0].lastName+" "+item.date+" - "+item["title"]);
		Zotero.write("]");		
		Zotero.write("(zotero://select/items/");
		var library_id = item.libraryID ? item.libraryID : 0;
		Zotero.write(library_id+"_"+item.key+")");
	}
}
  1. When you’ve added the .js file to the translators subfolder, (re)launch Zotero and go to the “Export” tab (if you’re on Mac, this is in Preferences). In the export tab, find the “Item Format” dropdown menu, and look for the label in the code (by default it’s “Obsidian Reference”). Select that, keep the “Note Format” as “Markdown + Rich Text”, and then you can close this window. Once you’re back to the main screen of Zotero, select the reference you want to create a link for, use the Quick Copy feature (Mac: Cmd+Shift+C), and then you should now be able to paste a link into Obsidian that, when clicked, will open up the selected reference’s entry in Zotero.

Style

I’m sure everyone has their own stylistic preferences for how the source should display. I wanted mine to appear like this [Eco 2015 - How to Write a Thesis](zotero://select/items/1234567890). If you want to change this formatting, just play around with the code (and then relaunch Zotero). I really had no idea what I was doing in Javascript, so I figured out how to arrange it like this through trail and error. Good luck!

8 Likes

Works like a charm. I have been looking for this for quite some time. Thanks.

3 Likes

You can also use the obsidian-citation-plugin. The zoteroSelectURI variable gives you the zotero URI which you can use to create a clickable link to open the item in zotero, (e.g. [@{{citekey}}]({{zoteroSelectURI}}))

Here’s an example template that uses it:

---
citekey: {{citekey}}
year: {{year}}
authors: {{authorString}}
title: "{{title}}"
aliases: ["@{{citekey}}"]
authorFirst: {{entry.author.[0].family}}, {{entry.author.[0].given}}
authorLast: {{#each entry.author ~}} {{~#if @last~}} {{~family}}, {{given~}} {{~/if~}} {{~/each}}
publication: {{containerTitle}}
doi: {{DOI}}
zoterouri: {{zoteroSelectURI}}
---

**{{title}}**
{{authorString}}
({{year}}) {{containerTitle}}
[@{{citekey}}]({{zoteroSelectURI}})
6 Likes

and fyi, in case you want to go in the other direction too, I made a Zotero add-on that lets you open your Obsidian notes from the Zotero items: ZoteroObsidianCitations

ZoteroObsidianCitationsMenu

6 Likes

Enjoy! Happy you found it useful :slight_smile:

Thanks for sharing! I’ll have to check this out when I’m a bit more familiar with Zotero and what not

1 Like

I’m so happy that I came across your “translator” for Zotero. I would like to modify the style of the output in Obsidian, so that it looks like the bibliography for “The Lancet”. Unfortunately I don’t know coding, so it’s impossible for me.

Hello, it’s been a while since this post was posted. I tried to follow the instruction but it does not seem to work. I cannot copy the item (although in Zotero’s edit menu, there is an option “copy as Obsidian Reference” with shortcut Cmd+shift+C. I chose that and still nothing happen). Could you help me as this is the exact thing I would like to do. Thank you.

I works fine following the instructions !

Hi, if I only want to insert a Zotero link using the Citations plugin using the format of [@{{citekey}}]({{zoteroSelectURI}}), how to create a link without inserting a note template? There is only a shortcut to insert md citations and I can’t customise a shortcut to insert {{zoteroSelectURI}}. Thank you!