New plugin: AutoMOC - find and add missing links

Hey everyone, first time posting on the forums. I just wanted to share that I created a plugin that I think many users will find useful. I call it AutoMOC.

The inspiration from the idea came from trying to manage my MOCs and not being sure which linked mentions I had already created a backlink for in my MOC. Oftentimes when creating a new note and linking it to a MOC, I would forget to explicitly make the backlink. Over time, this led to many missing links. Using the backlink pane wasn’t enough to fix this as it didn’t make it obvious which links were already present.

I had explored around to see if a plugin had already been developed for this, but the closest thing I could find was people using a dataview script to show missing links. I wanted there to be an easier way. Simply push a button or use a keyboard shortcut and your missing links were added.

So I made it. It’s a simple plugin. All it does it look at the links currently in a note, look at the rest of your vault for linked mentions, and add the ones that are missing. I just released the first version and I’d love to get some feedback from people on its usage (efficiency, bugs, additional use cases, etc.). I originally made it for the context of MOCs but it can be used for any type of note. My vault is relatively small, so I didn’t get to scaling.

Here’s the link to the GitHub for it and the plugin is available through the Obsidian community plugins.
GitHub: GitHub - dalcantara7/obsidian-auto-moc

4 Likes

Thank you for your nice plugin! The functionality of this plugin is exactly what I was hoping for.

On the other hand, I think the core function of this plugin is to “link back to all linked mentions quickly,” but I couldn’t immediately notice that from the name AutoMoc. IMHO, it would be better to emphasize that somewhere, because there are other situations where being able to easily link back is useful.

Feature request: if possible, I would like to see a command which creates links to files that has a tag with the same name as the active file name. It would be possible to create a MOC-like page for a tag easily.

Hi, glad you’re finding the plugin useful! When I first looking for a solution to this problem I stumbled upon the forum post you linked to. I wanted to comment on it after I made the plugin, but that thread had closed. Happy you were able to find my post.

I like the verbiage of “link back to all linked mentions”. I might put that in the readme as well as the plugin description in the next update. Thanks for the suggestion.

As far as your feature request, I think that would be possible. It may have to be implemented as a different command. Right now there is only one command that can be run (linking by links). I think it would be simple enough to make another command that goes through and checks tags instead of links. Ultimately this would mean the user maps the command to a different hotkey than the one that does it by links. Does that sound like a good implementation to you?

I think that’s fine! I think the options are either to create a link for a tag with the same name as the file, or to open a modal for input and create a link for the tag name entered. Both seem to have advantages and disadvantages.

There’s probably a middle ground. How about: create a second command that opens up a modal that is prefilled with the current note’s name (although the user can change it), then it inserts links to notes with tags matching that which was specified?

That way the note doesn’t have to be named after the tag you want. It gives greater flexibility of use and also makes the link by tag use case sufficiently different from link by link use case

1 Like

So as update, I’m thinking of not pre-filling the modal with the current file name. It doesn’t work well with suggestions and makes the usage kind of clunky. So instead the implementation will be: have a second command that opens up a modal (that is not prefilled) where a user can type a tag or look through a list of tags and then upon selection, AutoMOC imports all notes with tags matching the selected tag

The feature has been implemented. Please update the plugin and let me know if you encounter any bugs.

Thanks again for the suggestion!

1 Like

Thank you for the update. I tried the link to tag feature.
In my case, I was getting the following console error.
Depending on the tag word, it seems that in some cases none of the links are created and in other cases only one link is created, but in both cases I get the same error in the console.
Any ideas as to why?

plugin:auto-moc:148 Uncaught TypeError: Cannot read properties of undefined (reading '0')
    at AutoMOC.addMissingLinks (plugin:auto-moc:148:46)
    at AutoMOC.runAutoMOC (plugin:auto-moc:168:12)
    at TagSuggestModal.onChooseItem (plugin:auto-moc:101:17)
    at TagSuggestModal.e.onChooseSuggestion (app.js:1:1492273)
    at TagSuggestModal.e.selectSuggestion (app.js:1:1491823)
    at t.useSelectedItem (app.js:1:1389248)
    at t.onSuggestionClick (app.js:1:1388986)
    at HTMLDivElement.s (enhance.js:1:7956)

Also, when I try to create links (the original autoMOC function) from a particular page, it creates only a few links and then exits (there are more actual mentions) and I get the following error message. Not sure how this was in the previous version.

plugin:auto-moc:148 Uncaught TypeError: Cannot read properties of undefined (reading '0')
    at AutoMOC.addMissingLinks (plugin:auto-moc:148:46)
    at AutoMOC.runAutoMOC (plugin:auto-moc:168:12)
    at Object.editorCallback (plugin:auto-moc:185:16)
    at Object.t.mobileOnly.Mb.isMobile.t.checkCallback (app.js:1:1640123)
    at jz (app.js:1:1639584)
    at e.onChooseItem (app.js:1:1685533)
    at e.onChooseSuggestion (app.js:1:1492273)
    at e.selectSuggestion (app.js:1:1491823)
    at t.useSelectedItem (app.js:1:1389248)
    at t.onSuggestionClick (app.js:1:1388986)

Immediately after posting my last comment I figured out the issue, haha. It had to do with a separate feature I had implemented for incorporating aliases into the links. I was trying check the frontmatter to see if it had any aliases, but I wasn’t checking to be sure if the aliases field of the front matter contained anything. I presume you have some notes where the frontmatter is:

----
aliases:
----

i.e. you allocate the aliases field, but don’t provide any aliases.

I have since updated the plugin. You may need to uninstall and reinstall the plugin to see the changes. Let me know if it works now and if you do encounter another issue please do report it on GitHub. Thanks!

I am seeing an error even in v1.1.0 in my environment. I added an issue on GitHub.

Responded via the GitHub issue you created. Please see my response there.

TL;DR Obsidian update 0.14.15 (released 2 days ago) changed the way file aliases are handled. Plugin has been updated to reflect this change.

1 Like

The plugin does not see my tags that I added to frontmatter


image

Hi Gregor, thanks for point this out. It looks like by default the Obsidian API does not support getting tags from the frontmatter. It will only show tags within the body of the file. I will add support for frontmatter tags in my next release.

1 Like

Hi Gregor, just want to let you know that I released a new version of AutoMOC (1.3.0) which implemented support for frontmatter tags (among other things). Please test it. If you encounter any issues, please create an issue on GitHub so I can address it (Issues · dalcantara7/obsidian-auto-moc · GitHub). Hope you find this useful!

1 Like