Howdy! I’ve taken a short hiatus on the plant-watering-automation project but I am still doing automation-related stuff nonetheless!

I use Obsidian MD to take notes, journal, and otherwise record my information and thoughts. It is a great application that uses Markdown as the document style (that’s what the “MD” in “Obsidian MD” is for). It lets me keep my notes stored locally as opposed to in the cloud, and I am able to sync between my various PCs and mobile phone (for a yearly fee). Obsidian has some very intricate note-taking features like tagging, linking notes together and viewing them in a graph, and there is an extensive ecosystem of plugins that further enhance its features.

One cool feature of Obsidian that I use (more than any other aspect) is the Daily Note. There is a basic Daily Note feature available in vanilla Obsidian, but I use a plugin called “obsidian-periodic-notes” which add weekly, monthly, and more periodicities of notes. I just wrote an Obsidian Forum post about how to automate opening the current day’s Daily Note using the “obsidian-javascript-init” plugin (which allows users to write a JavaScript file that is run whenever Obsidian starts up). This automation mini-project was quite engaging for a few days – I have been using JS recently at work and this let me deepen my skills in the matter, I also used ChatGPT to help me figure things out a bit.

I learned a lot about DOM structures and how applications using the Chrome V8 engine work under the hood, and I plan on enhancing my Obsidian experience further with more automations like this.

Here is the contents from that Forum post, as I feel the post was succinct enough to remain engaging, and there is no real need to rewrite the whole darn thing 😎

“””

I used the obsidian-javascript-init plugin to automatically open the current daily note when I open OB. I have cursorily tested it and it seems to works on desktop and mobile. It first sets the middle leaf as the active leaf (on desktop), gets the daily note for today (retrieves or creates if does-not-exist), and opens the daily note as the active tab in the middle leaf.

Here is a snippet of the code in actions (function definitions available on github):

app.workspace.setActiveLeaf(getCenterLeaf())

let activeTabFiles = app.workspace.activeTabGroup.children.map(tab => tab.view.getState().file)
let dailyNoteFilepath = "001 Personal/Periodic/Daily/" + todaysDate() + ".md"
let dailyNoteTemplateFilepath = "008 Obsidian/Periodic/Daily Note Template.md"
let dailyNoteFile = await getNoteFile(dailyNoteFilepath, dailyNoteTemplateFilepath)

let dailyNoteTabIndex = activeTabFiles.indexOf(dailyNoteFilepath)

if (dailyNoteTabIndex === -1) {
    app.workspace.getLeaf("tab").openFile(dailyNoteFile)
} else {
    setActiveTab(dailyNoteTabIndex)
}

setTimeout(3500, ()=>{})  // tab's cmEditor, used to set caret position, may not be defined immediately on startup(?)

await addToNote(dailyNoteFilepath, "")  // add new line, in case of existing content in note

putCursorAtEndAndScroll()

I had to fork the obsidian-javascript-init plugin and make a small edit to allow async functions, like creating, opening, and editing notes, to run in the init script:
Original:

    runCode() {
        const source = String(this.settings.code);

Modified:

    runCode() {
        const source = `(async () => { ${String(this.settings.code)} })();`;

Here is the link to my fork of Ryan P Mcquen’s plugin (it’s not offically published as a plugin). My fork also contains my init script code (initScriptV1.js)

One thing that may not be kosher as far as working with the OB API was how I switched between tabs in the active leaf (if the daily note is already open in a tab, the script switches to that tab instead of opening a new duplicate tab). I modified the HTML classNames and style properties of the tab elements directly to force the daily note tab to be active, as I could not find any documentation on how to do so with the API. I was not 100% thorough, and you may notice that if the daily note is visible in the file explorer, it may not be highlighted to show it is active (it becomes highlighted as soon as you click or otherwise focus on the note). But for my purposes, this method is sufficient, and Obsidian has not crashed on me as a result (yet)!

Please let me know if you have any suggestions for improvement, or if you found this useful in your journaling journey! Cheers 🍻

“””

I have more quality-of-life improvements planned for my Obsidian setup, including hopefully utilizing ChatGPT or another LLM to categorize my notes automatically. This is not a flaw of Obsidian and moreso a flaw of my current note-structure (and generally lack-of-enthusiasm for organization) but the biggest barrier to me writing stuff down is figuring out how to tag notes and where to file them. I used to use Google Keep as my primary note-taking application. I liked how easy it was to write notes down because there was a lack of organization inherent to Keep (I never used tags…) but it was eventually the difficulty of finding notes that led me to look elsewhere.

Anyways, like the Forum post says, if you have and ideas for improvement or other comments, I’d be happy to read them! Also, cheers🍻

Leave a Reply