Hi everyone,
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.
General Approach
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).
Initial Setup
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â.
Final Comments
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
DevonThink-TheBrain Integration Macros_Smart Rules_v1.1.zip (8.5 KB)