Getting Absolute File Path for New Obsidian Note

I’m trying to use the Obsidian URI to create new notes in KeyboardMaestro and Shortcuts. I can get the first part to work, where it locates my vault (I just have one vault called ‘Obsidian’.

obsidian://new?vault=Obsidian

That gets a new note created at the root level. But I can’t get the file path parameter to work. I have a folder structure that I’m trying to put new notes into: Obsidian > Work > Meetings.

I have Obsidian inside my iCloud Drive, but I can’t figure out how to get the actual absolute path. It seems as though my iCloud Drive data would be in ~/Library/Mobile\\ Documents/com~apple~CloudDocs/, so I tried ~/Library/Mobile\\ Documents/com~apple~CloudDocs/Obsidian/Obsidian/Work/Meetings. I think the URI would be:

obsidian://new?vault=Obsidian&path=~%2FLibrary%2FMobile\\%20Documents%2Fcom~apple~CloudDocs%2FObsidian%2FObsidian%2FWork%2FMeetings

But for the life of me, I can’t get this to work. I assume iCloud Drive’s location is throwing it off and that I’m not converting it correctly. Anyone solved a similar issue?

I’ve created a vault called Obsidian in a folder called Obsidian in my iCloud’s Temp folder. I’ve also installed the Advanced URI plugin.

Within that vault I’ve created the folder structure of Work/Meetings, and within that I created a note called “meeting 1”.

I can use the plugin to get the URL for the file.

This gave me the URL of:

obsidian://advanced-uri?vault=Obsidian&filepath=Work%252FMeetings%252Fmeeting%25201.md

Using the documentation for the Advanced URI plugin on its Github repository, and in particular, the details about how to write content to Obsidian via the URL Scheme, I can take that URL above, change the “1” in the encoded filename to a “2” (just before the “.md”), and add the &mode=new parameter to build a URL that when launched creates a new note called meeting 2 in the same folder as meeting 1.

obsidian://advanced-uri?vault=Obsidian&filepath=Work%252FMeetings%252Fmeeting%25202.md&mode=new

Note I am using the advanced-uri version of the Obsidian URL, and there are no absolute paths. Because Obsidian knows where the vault called Obsidian is, I don’t need to tell it where to find it. If I was creating the file outside of Obsidian, then I need to know the location of the “Obsidian” vault in more detail and need either an absolute path or a relative path to something else (e.g. my home directory).

Hopefully, that puts you back on the right track.

1 Like

Before anyone asks…

This is something a little more nuanced than the answer, so I separated it out into a second post so as not to be overly confusing, but you may notice that in the link and creation URL, you may notice %252F and %2520. Well When you URL decode them, they become %2F, and %20, which can then be URL decoded to a forward slash and a space respectively, which is a more familiar file path.

If you use those second single encodings vs the original double encodings in the trigger URL it still works, and to me makes more sense, but above in the post above I was just setting out the approach more than anything else.

So why is the Advanced URI double encoding the path when it copies it to the clipboard? Well, all I can say is that it is on purpose to cover some cases that the plugin’s developer came across.

Thanks Stephen! This solved my problem perfectly. Had not heard of that plugin. Really appreciate you taking the time to solve the issue and walk through how you got there. (Also, I’ve actually been to your site before and found a lot of your articles to be super helpful, so keep doing what you do!). Thanks again.

1 Like