Watch folders for automatic import

One key feature is getting data into Logseq from different sources. Currently this is possible through the API, which is not always the best case and also requires Logseq to initiate the import synchronously.

Sometimes the easiest way is to asynchronously create markdown files by a 3rd party script.

Logseq will watch one or more folders, when new markdown files are detected in these folders they are automatically indexed and become available just like regular pages created by the user.

Use cases:

  • A program scrapes daily news feeds into a (read-only) folder. While the original articles are read-only to avoid modification, they can be included and referenced like any other page or block.
  • A ticketing system creates a markdown file for each new ticket. The files are writable and are updated by operators as they work on the tickets.
  • A (future) Zotero plug-in could automatically export notes for inclusion in Logseq.

Implementation details:

  • Logseq will watch one or more folders, which could be marked as read-only (alternatively there could be a read-only tag in the in the markdown files.
  • Addition of any files to these folders will trigger indexing of the files
    • Can use OS to register callback, e.g. System.IO.FileSystemWatcher.
  • Watch folders do not need to be located in vault
    • Avoids overwriting files in vault by scripts and to makes it possible to contribute without having read or write permissions to the vault itself.
    • Folder can be on a network drive, so that a 3rd party without write permission to the vault can still contribute. This could be e.g. a legacy ticketing application that runs on a different system and exports its tickets to the network drive.
  • The markdown files can have custom workflow tags (e.g. UNREAD/READ).
  • Operation is asynchronous, Logseq does not need to be running when files are added and will update its database when it is re-started.
  • Any new pages created manually by the user are located in the vault as before.

Logseq already appears to watch its own files. I sometimes modify mine with a text editor and Logseq dynamically reflects changes. That said, you could probably write and schedule scripts to post data to Logseq files from external sources and Logseq will handle it either dynamically or eventually.

You can use Logseq text files as a sink and other files and streams as sources without Logseq caring one bit about these background jobs.

2 Likes