I recently started using Obsidian for my note taking. I have a raving need for taking notes, but over time, it has spread to physical notebooks, various apps, post-in notes, and back again. This proliferation lead me to building Lakoy as an operating system for my life. I quickly drained all desire for rolling my own knowlege management system, and resigned myself to Apple Notes and my notebook – until now. For some reason, I decided go give Obsidian another shot, and this time it seems to click. To the extent that this blog entry is written in Obsidian, and with the help of plugins, teleported directly to my website, – in short, I’m in love.
Now, my Lakoy project has left me opinionated, and one think I want, is for every note to have a unique ID, to help me in the future. Surprisingly, setting a UUID for each note is not built-in to Obsidian, so I have so far used Templater (another plugin, plugged), that supports macros when applying a template to a note.
The only guide I found on how to spit out a UUID with Templater, relies on the system command uuidgen
, which unfortunately is not accessable on mobile devices. So all my notes taken on my phone ends up corrupting my perfect note world.
Now I found an easy and obivious way to get this working, and that’s why I write this. Templater also allow user-defined javascripts, so instead of relying on uuidgen
, I created a "Scripts" folder in my Obsidian Vault, and added a small script (called uuid.js) to it:
/**
* Generate a UUID4 for new notes
* - Should work on mobile as well as laptops
*/
function gen_uuid () {
return self.crypto.randomUUID();
}
module.exports = gen_uuid;
In Templater settings, it is possible to point to this folder under "User defined scripts", and voila, you can call <% tp.user.<script_filename>() %>
in your templates.
With uuid.js as the filename, I simply add <% tp.user.uuid() %>
to my template properties to generate a UUID. It works like a charm, on iOS too..
Hope this helps others.