Embedded button/link to run a command that creates a new note with a specific naming scheme

Trying to get into journaling. Tried different techniques throughout the years but the habits falls out. So I decided to create a dedicated vault for journaling and assigning a Windows hotkey to open it directly using the Obsidian’s URI commands to reduce friction.

Currently, I have been able to utilize the Zettenkasten prefixer to some extent, but I would like some extended functionalities to tailor it to my needs, but I’m unsure on how to approach this.

Functions I’m looking for:

  • A file/entry count prefix in the filename. This marks the current journal entry, thus giving me a visual indicator of how many journal entries I have made throughout the years at a glance, thus giving me a sort of motivation boost.
    Example: Today is 20th June. File named ‘01 2022-06-13’ is currently open as the latest journal entry. The action is triggered. New file named ‘02 2022-06-20’ is created and opened.
  • A button/link, embedded in every single journal note file itself, that, when clicked, will trigger the action mentioned above. While it “may” be possible to assign the action to a hotkey, just having a button labeled Create new entry just staring at my face may trigger a subconscious push to actually continue on journaling.

I’m sorry if what I’m asking for is too niche and insignificant, but I really wanted to get into the habit of journaling and it’s quite frustrating that I’m unable to. I’m trying to poke around at my own psychology to experiment and find what actually works so I can steadily work on my self-improvement.

Factor I am aware of, in order to implement this action:

  • Obsidian (or any other program I utilize and connect) needs to be aware of the latest created file or be able to read the filenames and determine which one has the highest numerical prefix

Approaches that occurred to me:

  • Templater ‘User Script Functions’ or ‘User System Command Functions’. I did not dive into these portions of the addon and am not sure whether its possible or how it can be done.
  • External script file that Obsidian can call to trigger this. I know a bit of python, but nor javascript, so I am able to make a script that can create new files and check filenames, but I don’t know how I can make the script make Obsidian to open the newly created file, nor do I know how I could connect the two.

I think is possible

I am not an expert,

What i have done in your case, is going to need dataview, templater, and buttons.

What need in cofiguration

Create a folder for templates, select the folder it in templater configuration.

In templater configuration ativate trigger template on new file creation.

Create a folder for the jornal, something like Journaling.

Create a file in templater folder, with a name, like “jornaling entry”.

In the file paste this code:

const dv = app.plugins.plugins.dataview.api; // Dataview Api

let journalThatHappened = dv.pages('"Journaling"').file.name; // Get all journal in folder journaling
let journalCurrentNumber = await journalThatHappened.length; // Get the number of journals
let actualDate = await tp.date.now('YYYY-MM-DD'); // Get the atual date

await tp.file.rename(`${journalCurrentNumber} ${actualDate}`); // Rename
name New Journaling
type note(Journaling/New Note) template
action journaling entry



You can replace the names, but replace in every place that apears.
For exemple the folder Journaling, apears in 2 places, in get journal name and in the button.

Hi, thanks for your reply. It works!

I’ll try tweaking it around a bit to account for unexpected scenarios and post an update.

Thanks again!

1 Like

Here to provide an update. The code will not work as intended if there are different number of files in the folder compared to the latest entry.
For example: Let’s say the latest journal entry is #5. But #3 is missing/doesn’t exist. This means there are total of 4 files in the folder. So if I click the button, the new entry created is labeled with ‘5’ instead of ‘6’.

Possible workaround:

  • Have a master note with a YAML attribute of ‘latestEntry’.
  • When the button is clicked, the new note reads that attribute of the master note and renames itself with a +1.
  • Then the new note updates the YAML of the master note (maybe use MetaEdit?) to the new latest entry

But I’m not sure how to do this, or if there’s a simpler way.

Will your latestEntry always be the one with the most recent date in the title?

If so, you could maybe change the journalCurrentNumber line to split the file names by ’ ', sort by the date (aka [1] of the split) desc, limit (1), and then pull out the number of the most recent entry by [0] of the split and add one?
Something like this (line breaks option and just to make it easier to read on the forum.):

let journalCurrentNumber = journalThatHappened
.sort(n => n.split(' ')[1], "desc")
.limit(1).map(n => Number(n.split(' ')[0]) + 1);

I got it to work like an hour ago. Everything is fine except for just one small problem which I have addressed in this new post.

Will your latestEntry always be the one with the most recent date in the title?

Yup. I’m using MetaEdit plugin to update it.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.