Okay, I took a shot at this for fun, and it works! Here’s a script in javascript that will tell Zotero Integration to create a literature note on every item in a bibtex export from Zotero.
You can run it in Obsidian using any of the plugins that can execute javascript code. I tested it through Templater, but a Quickadd macro would also be a good choice.
There’s two things you need to do:
- Specify the absolute path to a better bibtex export from Zotero
- Specify the name of the import format Zotero Integration should use
Both are marked “todo” in the script, so just search for that.
const fs = require('fs');
function extractCitekeys(bibtexFile) {
const bibtexData = fs.readFileSync(bibtexFile, 'utf-8');
const regex = /@([a-zA-Z]*)\s*\{\s*([a-zA-Z0-9_:.#$%&-+?<>~/]*)/gm;
let match;
let citeKeys = [];
while ((match = regex.exec(bibtexData))) {
const citekey = match[2].trim();
citeKeys.push(citekey);
}
return citeKeys;
}
// Usage
// (todo) Replace this path with the actual absolute path to your bibliography
const bibtexFile = "C:/Users/Your/Full/Path/To/Bibliography.bib";
const itemsToImport = extractCitekeys(bibtexFile);
// Import every item in the bibtex file
if (itemsToImport.length > 0) {
let itemCount = itemsToImport.length;
new Notice(`Importing ${itemCount} items`, 5000);
for (const citekey of itemsToImport) {
itemCount--;
// (todo) Replace 'Testing ground' below with the name of your import format that Zotero Integration should use
app.plugins.getPlugin('obsidian-zotero-desktop-connector').runImport('Testing ground', citekey);
// If you are importing from a group library, add a number after the citekey that corresponds to the order the group libraries were created in, counting up from My Library, which has the libraryID 1. So if the group library you are targeting was the first group library you created, its libraryID is 2. In that case, you would need this:
// app.plugins.getPlugin('obsidian-zotero-desktop-connector').runImport('Testing ground', citekey, 2);
new Notice(`Imported ${citekey}, ${itemCount} remaining`);
}
new Notice("Import complete!", 3000);
} else {
new Notice("Nothing to import");
}
Warning
- I only tested this on a small collection, as I did not want to create almost 2000 files in my vault.
- Re-importing existing files will update / overwrite them, depending on the output path in your import format settings and depending on whether you have persistent fields in your template.
- You can probably do the same thing using the classic view in Zotero’s citation picker. Therefore, the value of this is mainly in a) a proof of concept, and b) automation workflows.