Visualising Links between Zettels with Keyboard Maestro and Graphviz
I have been wanting to visualise the links between selected notes in my zettelkasten for quite a while, mainly in order to simplify "tidying up" or organising a network of zettels (adding appropriate links, consolidating similar zettels, adding or removing tags from zettels appropriately, etc.).
I was quite involved in this discussion about visualising zettel-networks and followed and tested @alexchabot's work on zkviz, but still didn't find all my needs met – I had the desire to customise the setup a bit more Last week I then decided to try to create my own visualisation-setup, using Graphviz and Keyboard Maestro, which both had a key role in the above mentioned discussions and projects. I wanted to try not to use Python or similar scripting languages in addition to Graphviz and Keyboard Maestro in order to make it easier to customise things for people who aren't familiar with those languages (me included).
What I came up with is a KM macro that is supposed to be triggered when the desired zettels are selected in The Archive, it will finish by opening a .svg-file with the visualisation in Safari.
As with @alexchabot's zkviz, the macro will assume that all zettel titles will start with the 12-digit UID and then have a verbal title. If your titles look different, the macro won't work. The macro also assumes that all your notes have the extension
Given all this, the following steps need to be done in order to get it running:
- Graphviz needs to be installed. If you have Homebrew, run
brew install graphvizin the Terminal.
- In order for the graphviz command
dotto be found by the Keyboard Maestro engine, the folder that Graphviz was installed in needs to be added to the folders that KM searches for shell-commands. This can be done by adding the variable
ENV_PATHunder Keyboard Maestro's "Preferences -> Variables" and setting it to
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin(the folder /usr/local/bin was previously not searched).
- Download the main KM macro under this link, open it in KM and change the entries that I marked in the following image according to your needs (5 pathnames):
- Download this additional KM macro that generates a list of the notes in your zettelkasten from time to time. This list is needed in order for the main macro to work and can also be used for many other purposes (which is why I keep it separate). Adjust your zettelkasten-folder if necessary.
- If your notes all have the same extension, but not
.md, you can easily change the extension in the relevant macro (to e.g.
.txt). If your notes have several different extensions, it's not straightforward to make it work (at least from my perspective), but it should be possible.
That's pretty much it. The output for a small group of my zettels looks like this:
- If you create your own .svg-files with the macro, the nodes are clickable and will lead to the corresponding note in The Archive (URL-scheme).
- All the selected notes are in the darker blue, non-selected notes that they link to are shown in a light blue (if desired). The colours can easily be changed in the macro.
- You can also try other programs than dot included in the Graphviz package by changing the command
dotin the "Execute Shell Script" action (not the file extension .dot which can be used by all the programs!) to
osage– they will all result in different arrangements of the nodes. Play around and see what you like best.
- You can also play around with different node shapes, arrows, nodelines, etc. – look at what the DOT-language has to offer, e.g. here.
Looking forward to feedback and images!