Automatically tag Zotero items with in_logseq when they are referenced in Logseq pages with the #zotero tag.
This tool syncs your Logseq knowledge base with Zotero by:
- Querying Logseq (via CLI) for all pages with #zotero tag and Zotero URL property
- Extracting the Zotero item keys from those URLs
- Checking which items already have the
in_logseqtag in Zotero - Batch tagging only the items that need it
This is idempotent - you can run it multiple times safely. It only tags items that don't already have the tag.
- Logseq Desktop app (CLI only works with desktop, not browser version)
- @logseq/cli installed globally (
npm install -g @logseq/cli) - Python 3.7+
- Zotero account with API access
-
Clone or download this repository to
/Users/niyaro/Documents/Code/logseq-zotero-sync/ -
Install Python dependencies:
cd /Users/niyaro/Documents/Code/logseq-zotero-sync pip3 install -r requirements.txt -
Set up credentials (shares credentials with zotero-tag-automation):
If you've already set up zotero-tag-automation, you're done! This script uses the same keychain credentials.
If not, run the setup from zotero-tag-automation:
python /Users/niyaro/.claude/skills/zotero-tag-automation/setup_credentials.py
You'll need:
- Your Zotero Library ID (find at https://www.zotero.org/settings/keys)
- Your Zotero API Key (create at https://www.zotero.org/settings/keys/new)
Run with auto-detected graph:
python sync_logseq_to_zotero.pyOr specify a graph name:
python sync_logseq_to_zotero.py "2025-10-26 Logseq DB"- Add new literature notes to Logseq with #zotero tag and Zotero URL property
- Run this script periodically to sync the
in_logseqtag to Zotero - Use the
in_logseqtag in Zotero to filter/organize your referenced items
==============================================================
Logseq to Zotero Sync
==============================================================
Querying Logseq graph: 2025-10-26 Logseq DB
Found 14 items in Logseq with Zotero URLs
Querying Zotero for items with 'in_logseq' tag...
Found 10 items already tagged with 'in_logseq'
Found 4 items that need tagging:
- AA8CFB7Y
- DUF7Q2B6
- M2QGSQA9
- ZTSWUK3C
Tagging 4 items with 'in_logseq'...
[1/4] ✓ AA8CFB7Y: Here we are together
[2/4] ✓ DUF7Q2B6: Reflections on Orthography in Formosan Languages
[3/4] ✓ M2QGSQA9: Taiwan Archaeology
[4/4] ✓ ZTSWUK3C: Who owns "the culture of the Yellow Emperor"?
==============================================================
Summary:
Successful: 4/4
Failed: 0/4
Tag: in_logseq
==============================================================
- Logseq Query: Uses
logseq queryCLI command to find all pages with the Zotero URL property - Extract Keys: Parses the output to extract Zotero item keys (e.g., "M2QGSQA9")
- Batch Check: Queries Zotero API for all items already tagged with
in_logseq - Diff: Compares the two lists to find items that need tagging
- Tag: Only tags items that don't already have the tag
This batch approach is efficient because:
- Only one query to Zotero for existing tags
- Only tags items that need it
- Idempotent - safe to run repeatedly
Credentials are stored securely in macOS Keychain using the service name zotero-tag-automation (shared with the zotero-tag-automation skill).
To view/manage:
- Open Keychain Access.app
- Search for "zotero-tag-automation"
"Graph not found"
- Make sure you're using Logseq Desktop app (not browser)
- Run
logseq listto see available graphs - Specify the exact graph name as shown in the list
"Credentials not found"
- Run the setup_credentials.py script
- Check Keychain Access.app for the credentials
"Command not found: logseq"
- Install @logseq/cli:
npm install -g @logseq/cli - Verify:
logseq --version
- zotero-tag-automation: Tag Zotero items after search results
- logseq-cli skill: Interface with Logseq from Claude Code
MIT License