since there has been repeated interest expressed in these forums (e.g. here and more recently here) on how to integrate DevonThink and TheBrain, I want to share an experimental approach that has worked for me.
Try this at your own risk and please use a dedicated brain for testing purposes, not the one with your 10000 carefully curated thoughts. No warranties etc
That said, the following setup has gone through several iterations over the past six months or so, mainly to reduce required maintenance and streamline things as much as possible (given that TB does not have any scripting support).
Primary Use Case
The main use case for the integration is to leverage TheBrain’s visual interface for Zettelkasten workflows, as it is excellent for establishing different types of connections between atomic notes. While I personally prefer DevonThink for everything else, I do prefer the visual interface in TheBrain (in combination with DT’s features enabled through the integration) for this specific use case. DevonThink plays its part by addressing several weaknesses of TheBrain such as its lack of finely tunable search operators, smart rules and AI-based recommendations among others. It’s the best of both worlds.
The general approach is to index the “Brains” folder under /user/Brains in DevonThink. In TheBrain, I don’t use the Notes section but rather create a Markdown attachment that mirrors the thought’s name. A smart rule in DevonThink replicates all indexed Markdown items to a group for atomic notes called “insights” and from there, one can work with them like with any other database item. Jumping between TB and DT is enabled by adding each TheBrain thought’s own link to the top of the Markdown attachment (enables jumping from DT back to TB) and vice versa through a KB Maestro macro, which searches for the TB thought’s name in DevonThink. Finally, a maintenance workflow using smart rules and KB Maestro copies Markdown attachments to the Notes periodically, which is necessary in order to benefit from TB’s backlinks and mentions (thought attachments are not indexed).
Replicating insights to a dedicated group in DevonThink
First note that under the Brains folder, there are several subfolders like “B10”, “B7” etc. Each of them contains the contents of one “Brain”. I recommend that you apply the following smart rule only to the subfolder of the Brain you want to index. You can find out which one it is e.g. by adding an attachment to any thought in that brain and then checking, in which of the subfolders it has appeared.
Also, the smart rule should exclude any items named “Notes”, for reasons that should become clear later. This is what the smart rule looks like in my setup:
In effect, as soon as a new markdown attachment is added to a thought in the respective brain, it is indexed automatically and then replicated to the folder for atomic notes in DevonThink. You’ll find the smart rule in the attached Zip package.
Adding new MD attachments in TheBrain
Set a hotkey for “Add Markdown File” in the TheBrain preferences to make this a one-step process.
Adding TheBrain thought link to new thoughts
After creating the attachment, I use a KB maestro macro to add its own link to the top of the Markdown document with one press of a hotkey. This is done to allow jumping from that thought viewed in DevonThink directly to the same thought in TheBrain.
The macro is fairly self-explanatory (some steps have explanatory comments) and you’ll find it in the attached zip under the name “Add local thought URL to MD notes”. Note that the macro contains variables to preserve the clipboard and some syntax to tell DT not to show the link in Markdown note’s previews - related macro steps are non-essential and can be removed.
Jumping from a thought viewed in TheBrain to the same thought in DevonThink
Here, the approach is to copy the thought name, activate DevonThink, activate the search, paste the thought name with some limiting criteria and then open the result in a new window.
To do this with one hotkey, you can use use the KB Maestro macro “Search selected thought in DT as insight (from TB)”. Please check the steps as they probably need to be adapted slightly to your setup.
Viewing an insight’s tags from within TheBrain
When viewing an attachment, hit the “Get Info” hotkey defined in the TheBrain preferences. This shows the finder Get Info window, with all tags added in DevonThink reflected automatically in the Finder tags.
Maintenance: Automatically copying the markdown attachment contents to Notes in TheBrain
This is non-essential but very useful to benefit from the full functionality available in TB regarding backlinks and mentions. Since attachments are not indexed, any changes made to markdown attachments need to be copied to the Notes through a maintenance process.
Note that each thought in TheBrain has its own subfolder under the Brains/TBx parent folder, and the thought’s attachments are contained in these subfolders. The subfolders have names such as “0a37f834-47c8-5598-9428-3eebf44b3152”. Notes on a thought in TB are automatically saved in the respective subfolder (the same as the attachments) as “Notes.md”. Replacing this file replaces the notes displayed when looking at the thought in TB.
I use two smart rules (run manually as needed, see below) in DevonThink to do the following: 1) Delete all existing Notes.md files. 2) Duplicate the markdown attachment within its enclosing folder (the assumption is that each thought has exactly one markdown attachment) and rename it to Notes.md.
IMPORTANT: As I learned the hard way, THEBRAIN MUST NOT BE RUNNING during this maintenance. Otherwise, it will freeze and there is a risk of duplicate attachment entries with invalid paths. The problem is not data loss (which I’ve never encountered) but rather that there is no way to remove the duplicate, non-functional entries in batch. So it needs to be done manually one thought at a time, which can be a lot of work in a large brain.
So the process to get started here is as following (later, this can be further automated):
- Close TheBrain and double-check that it is indeed not running
- Run Smart Rule “Remove all Notes.md files”
- Run Smart Rule “Duplicate MD attachments and rename duplicate to Notes.md”
- Double-check Brains/TBx folder to ensure thought subfolders contain one attachment and one Notes.md file
- Reopen TheBrain
Optimizing the Note refresh maintenance process
After the above is working as intended, it can be further simplified and automated:
I set up a keyboard maestro macro which automatically closes TheBrain and then calls the smart rules one after the other before reopening TheBrain. This macro can run automatically late in the evening, on idle or be triggered manually as needed. You’ll find it under the name “TB Notes_Refresh all thoughts’ notes to reflect current MD attachment”.
This setup is what works for me after quite a lot of time invested to adapt and iterate. I hope it will inspire others to experiment and perhaps suggest further improvements. Please share your thoughts