Auto-Linking Tool

Some of the reasoning behind consolidating the aliases into a single file:

Speed: Only one file needs to be opened to determine all of the aliases as opposed to cracking open every .md file in your vault in order to parse the frontmatter.
Portability: If for some reason my script or Obsidian ceases to exist and you need to port your notes elsewhere, you have a bunch of orphaned YAML spread across your vault.
Safety: If I can avoid opening your Markdown files, I can avoid any issues relating to data loss, privacy, etc. much more easily.
Visibility: It’s much easier to see the entire scope of your aliases when they’re in one file.
Fragility: If the aliases were defined in frontmatter and I decide that the format of them needs to change in the future, people are stuck updating potentially hundreds of files as opposed to just one.

Perhaps one day I’ll add the aliases to the frontmatter or provide it as an option. I suspect a plugin (hopefully an official one) may also solve the problem. For now, @Spec04 has provided a solution that works with this tool to allow you to put aliases in the frontmatter and extract them into aliases.yml.

3 Likes

Added a feature today to link only the first instance of a title in each paragraph (-p on command line).

2 Likes

Added a companion script to “unlink” a block of text in the clipboard. When the script is run, any wikilinks in text are removed.

It scrubs links of the type:

  • [[this]] becomes this
  • [[Great Page|that]] becomes that

It does not touch links of the type:

  • ![[untouchable]]
  • ![this link](is safe)
  • [so is](this one)

I use this to quickly unlink some text following auto-linking, when the text is linked too frequently for my liking.

1 Like

I agree with the aliases source file, but working on the fly & being able to explore, check, edit via the current note is extremely helpful. Perhaps an option could be a plugin panel which shows you the content from the aliases file of the current note you’re viewing and also allow you to edit or add more. Similar to the Backlink or Tag panel. We could have an Alias panel, with various options, and but it’s all tied back to the aliases file.

This way we can see essentially metadata on the note, but without cluttering the file & all the other reasons you listed and if anyone wanted to embed them in the note itself for whatever reason, an inverse of @Spec04’s solution could be an possible solution. Putting the all aliases from the single aliases file into all their respective notes.

There are some good ideas here. As a medium-term step, perhaps the aliases.yml file could become aliases.md with all of the aliases defined in YAML frontmatter. That way the file can at least be opened/edited in Obsidian and placed wherever the user likes. It wouldn’t sync the location to the current note or anything, but that’s probably the most that could be expected without this being a plugin.

I’ve been hanging back to see what happens with the plugin community and where the devs go with aliases. They’ve added aliases to the roadmap (although with no detail), but I would expect that their aliases feature will be the authority for any other plugins/tools that use aliases. That needs to play out before deciding how to proceed. I also don’t really have a lot of time to commit to porting to a plugin and maintaining it right now.

1 Like

If you’re an AutoHotKey user, this tool integrates nicely with that. I set up AHK scripts for linking and unlinking.

Linking (Shift+Ctrl+L links selected text):

+^l::
Clipboard=
Send ^c
RunWait, cmd.exe /c python obs-linkr.py c:\path\to\your\vault, c:\scripts\obs_tools\forward_linker, Hide
Send ^v

Unlinking (Shift+Ctrl+U unlinks selected text):

+^u::
Clipboard=
Send ^c
RunWait, cmd.exe /c python obs-unlinkr.py c:\path\to\your\vault, c:\scripts\obs_tools\forward_linker, Hide
Send ^v

Here are the scripts in action (Ctrl+A -> Shift+Ctrl+L, Ctrl+A -> Shift+Ctrl+U):

You’ll have to modify the paths to match your own, and may need to add Python to your Windows %PATH%.

2 Likes

Added a new feature today that was inspired by comments from @Fovea.

As an alternative to aliases.yml, the tool now supports using aliases.md at the root of the vault. The files use the same format, but aliases.md can be opened in Obsidian. This provides a few benefits:

  • The file can be edited on-the-fly, repositioned, etc. (best viewed in edit mode)
  • The page titles can be linked, eg.:
[[problem solving]]:
- solving problems
- problem solve
  • When page titles are linked, they will show in the backlinks section (linked mentions). This gives visibility into the aliases defined for a page being viewed (works best with ‘Show more context’ enabled in backlinks section).

You may wish to exclude the aliases file itself from being linked during the auto-linking process by adding the following to aliases.md:

aliases:
- 
2 Likes

With the introduction of aliases into Obsidian 0.9.16, it was time to rework the auto-linking tool. Here is an overview of what the tool does and what has changed.

The auto-linking tool is a Python script that scans your vault for Markdown files, collecting a list of all the note titles and any aliases that are defined in YAML frontmatter. Aliases were introduced in Obsidian v0.9.16 - https://publish.obsidian.md/help/How+to/Add+aliases+to+note.

To cut down on file access and increase speed, the aliases are stored in a file (aliases.md) in the root of the vault. This file can be regenerated at any time, or every time if desired.

The input to the script is the clipboard text, which is scanned for any instances of the titles or aliases. When one is identified, the text is replaced by a wikilink to the relevant note. The modified text is pushed back to the clipboard.

I use this when importing notes or other text so that it can be ‘linked’ into my graph. I also use it after composing notes, so that I don’t have to concern myself with linking as I enter text.

There are options that can be passed on the command line to limit the amount of link output, as well as a separate script to ‘unlink’ a block of text.

The latest version is available at https://github.com/perkinsben/obs_tools/tree/master/forward_linker. If you’re pulling this code down for the first time since aliases were introduced in Obsidian 0.9.16, you’ll need to install another Python dependency (‘pip install python-frontmatter’).

6 Likes

Any chance this might evolve into a plugin with quick shortcuts for autolinking and delinking? I think it would be really phenomenal if done!

6 Likes

It’s possible, but I don’t have time to work on a plugin right now. There is nice automation possible through AutoHotKey on Windows:

Great work - I might be misunderstanding the standard obsidian workflow here, but why is this not part of the core feature set? Surely we want the system to perform as many (meaningful) auto-links as possible to generate the emergent idea structure?

Manually doing this is only marginally better than taking notes in a filing system with tags.

Is it that with a large enough mass of notes, the number of auto-links would become unwieldy?

4 Likes

FYI Voodoopad handles autolinking well with thousands of links, don’t know the upper limit but it would be in the hundreds of thousands most likely.

appears to be mac only.

Yes, but Mac and Windows OS systems and HW are pretty much the same, so this was mostly about performance with auto-linking.

Does this plugin still work or anybody? It does not seem to generate the aliases file or link any aliases unfortunately.

Still working for me. Did it stop working suddenly? DM if you want some help with it.

@benperkins I’m following your development of this with great interest. It’s clearly a powerful tool but I’m not quite at the ‘running python scripts’ stage yet; I’m less than a week out from discovering Obsidian (and Zettlekasten!!) after years of PKM and note-taking app hell and honestly think I’ll end up splitting my life into Before Obsidian and After Obsidian. Keep up the great work!

2 Likes

Does anyone know if there’s any plugins that do this? I’m hoping since it’s almost been a year since this was posted that some community plugin has been made that does the same.

This function has been realized long ago (about June 2020). You can contact me on QQ (312815311).

I’ve just learned that python is case sensitive. And that is a problem for my inconsistent way of typing “aliases”.
When using the script, it only includes aliases which is defined by “aliases: [alias1, alias2, alias3]”. But sometimes I’ve written it “Aliases: [alias1, alias2, alias3]”. Is there any way to have it include both, or will I have to go through all my notes and correct them to the lowercase “aliases” version?

I feel like I just need to write “or Aliases” in the code somewhere, though I don’t speak Python at all, and therefore need some help figuring out where to do it.

1 Like