,

Automating Obsidian

Obsidian is a great tool, and I’ve only just begun to understand it’s many uses. On the surface it’s simply a program to help with note taking. With plugins, some custom scripting, and a little bit of time however it seems it can do just about everything. For instance, you can link one note to another with the proper markdown tools. That alone makes organizing things as easy as linking a descriptor page for a topic in where it gets mentioned in the current form. When you need to view the descriptor, there you have it! I’m only a beginner in terms of my user-status however, so I really just know there are plugins and loads of things to try.

Like…. maybe… finding out you can run shell commands from a hotkey-press in Obsidian. So if I WANTED to I could randomly launch a word processor other than this one from pressing whatever I want. I also found out that you can publish to a WordPress website by clicking a button as well! So if I type something up here, all I have to do is add photos and click publish when the time is right!

Now on to the task at hand: Automation of Obsidian. Like I mentioned, it is an incredible tool if it’s used right. Using it right, however, means taking time to build the framework for what work flow is best for you. Personally I’m figuring it out as I go, and hoping that if I find a hiccup or find myself lacking in the ease of use I can fix it with some programming- which is exactly what I’ve done.

I’ve started to use this program for, among other things, keeping a loose journal on my life. Not really a day-to-day, but fairly often. One thing I want to do is at the top of each page have a link to the previous note, and the next one. Ideally, using it would be as simple as pressing a hotkey, and then a new note appears with today’s date as the title, the first line being a link to the last entry, and the next line being the entry I have yet to make. To make it seamless it will also have to edit the previous entry to have the correct link for the next note, and in the future if I find out I want some specific formatting, I’ll be able to add to it no problem!

This is pretty much all I know how to do for a project write up like this. I could go into what I had to do to code it but that’s just keyboard mashing and googling things.

On to the code I perhaps. It’s not the prettiest, but it works!


import glob
import os.path
import os
from datetime import datetime

now = datetime.today().strftime('%Y-%m-%d')
check_name = now + ".md"
path = r"F:\Documents\Mind Palace\Personal\Journal"
check = path + "\\" + check_name
check_file = os.path.exists(check)
stuff = []
uri = "obsidian://open?path=F%3A%5CDocuments%5CMind%20Palace%5CPersonal%5CJournal%5C"
URI = uri + check_name
 
linking = glob.glob(path + "\\*.md")
for i in linking:
    stuff.append(os.path.basename(i))

last_note = stuff[-1]
    
if check_file == False:
    it = open(check, "a")
    it.write("<<[[" + last_note[:-3] + "]]|| \n ||{{PLACEHOLDER}}>> \n")
    it.close

    print(path + last_note)

    with open(path + "\\" + last_note) as f:
        lines = f.readlines()
    lines[1] = "||[[" + now + "]]>>\n"
    b_file = open(path + "\\" + last_note, "w")
    print(lines)
    b_file.writelines(lines)
    f.close()
    
    os.system('start %s' % URI)
    
elif check_file == True:
    print("The file already exists.")
    os.system('start %s' % URI)