Counting the number of wiki links per note

Not sure I've thought this through enough and would be interested in ideas or sample macros that can be repurposed.


I have a series of over 1000 notes that are named with the format 202002081650 Personal Writing and contain wiki links in the format of [[202002081650]]. I'm thinking about a macro that would count all the links in other notes that point to this note, or you might say links that are inbound this note. This would add in the number like so. [[202002081650]] (i6) Of course this would have to be updated with every new wiki link.

I'm thinking that I'd want to set the macro up to update all the instances of [[202002081650]] (i6) to the newest count of the use of that link. So when a new link is made to this note a script would run that would scan the entire 1000 notes and change each link count to [[202002081650]] (i7).

I'm thinking that I'd also like to add a reference to the number of out going link per note. Like [[202002081650]] (i7 o2) to indicate 7 links incoming and 2 links outgoing. This seen much easier.


This is my early thinking and I'm wonder what your suggests for an approach would be?
Should I create a db in a %Variable% to make lookup faster. Maybe the approach should be to update the link being added in real time and have the other notes updated nightly?
I worry about this corrupting the notes and the cpu time to cycle through all the notes when ever a new link is created.

Sample Note

Here is the contents of the note showing in bold what I'm thinking would be the output from this macro.

Personal Writing Knowledge

  • Every sentence needs to stand on its own. No bridge sentences.
  • If a sentence or scene doesn't move the essay forward - cut it!
  • In writing the memory is transformed and sometimes a lot
  • Up to 7 parts to a sentence, 6 commas, poetic.
  • Essay in the form of a letter or a couple of letters. [[202001221210]] (i6 o10)
  • Essay in the form of an instruction manual for a thing or a process.
  • use these tips/tricks sparingly
    • repeat a sentence or phrase for impact
    • use a run on list for impact
    • use a cartoonish sentence
    • have something happen that is tangential but still subtly connect to story

01-23-2020 - 8:05 AM
[[202001230805]] (i3 o3) Personal Knowledge

[[202001221210]] (i3 o1) Metaphysics Trick
[[202002081650]] (i2 o0) Editing Checklist
[[202002100737]] (i2 o2) Name the action

Just a question before I fire up my braincells...

In your Sample Note [[202001221210]] appears twice - once with (i6 o10) after it and the other time with (i3 o1) after it.

How can that be right? Shouldn't they be the same?

Yes they should be the same. My error when I made the 'mock up'. This is another reason to use Keyboard Maestro here as I can't be trusted to get the process right the first time nor will I keep it updated. Keyboard Maestro to the rescue.

Great! Thinking hat on...

What WiKi platform are you using? It may be possible that it exposes an API that can be useful in providing a solution to your problem?