Skip to content

Instantly share code, notes, and snippets.

@TheHuntyBadger
Last active November 4, 2022 23:51
Show Gist options
  • Save TheHuntyBadger/723e09cd05e55811b9c53b67ee152051 to your computer and use it in GitHub Desktop.
Save TheHuntyBadger/723e09cd05e55811b9c53b67ee152051 to your computer and use it in GitHub Desktop.
Generate a Luhman Style ID for Zettelkasten systems for implemenation using QuickAdd and Templater plugins

/*

This script returns a random Letter or Symbol listed in 'characters.

REQUIRES:

TO USE:

  • Save this in your-obsidian-vault/scripts.

  • In the Templater plugin settings, choose scripts as the folder for user scripts.

  • Create a note and paste this in: <% tp.user.MakeLuhmanID(length) %>.

  • Replace length number of random letters you want as an ID.

  • Use <% tp.user.RandomLetterGenerator(#) %> to generate a Luhman inspired ID any length`

  • Templater can also be used with QuickAdd to create a note from a template with a Luhmann style ID.

  • use the 'Temple option in QuickAdd as either a direct command or macro. Include `<% Math.floor((Math.random()*10)+0).toString(16) %><% tp.user.MakeLuhmanID(length) %>0' in the template, not in the template title, to generate a new top level Zettel ID for a Zettelkasten system. This formula can't be pasted into the title because it contains special characters that are not allowed. -This script will return a single letter from characters to use in generation unique IDs. -Use in combination with a random number generator as above to have a #$ starting ID.

  • To work with the Obsidian Luhman plugin, generate only lower case letters. If not using the Luhman plugin you can add uppercase, numbers to the characters var to generate a random ID with a set length and no specific meaning.

  • You can double up alternating between numbers and letters to create a starting Top Level Zettel with 4 characters to increase the number of unique entry points into your Zettelkasten (i.e <% Math.floor((Math.random()*10)+0).toString(16) %><% tp.user.MakeLuhmannID(length) %><% Math.floor((Math.random()*10)+0).toString(16) %><% tp.user.MakeLuhmannID(length) %>0)

*/ function MakeLuhmannID(length) { var result = ''; var characters = 'abcdefghijklmnopqrstuvwxyz'; var charactersLength = characters.length; for ( var i = 0; i < length; i++ ) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } return result; } module.exports = MakeLuhmannID;

@TheHuntyBadger
Copy link
Author

TheHuntyBadger commented Nov 4, 2022

To use this effectively with the Obsidian Luhman plugin, you want the unique ID to end on a number.

Here is an example:

Entry Zettel using QuickAdd & Templater to create a unique Top level ID:

Templater code created Unique Starting ID
ZettelkastenEntryPoint00

You must copy and paste it into the Title
ZettelkastenEntryPoint01

Then use the Obsidian Luhman Plug in to create Siblings and Child Zettels!
ZettelkastenEntryPoint02

I have QuickAdd ask me for the Central Idea to use as the Title. It also adds it to the note itself.
ZettelkastenEntryPoint03

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment