Open a vault using its filepath via the URI

Problem Description

TL;DR: The Obsidian URI (opening obsidian://) does not provide any way for the user to open an obsidian vault, if that vault has not been opened / cached before.

Example

Given a the vault Testvault at /path/to/testvault, if you have previously opened this vault (specifically, if it is recorded in the obsidian.json file) you can open this vault using these commands URIs:

By name

obsidian://open?vault=Testvault

or with the path:

obsidian://open?path=/path/to/testvault

The bug / problem occurs when trying to run the bottom command, without previouly having opened this vault. Obsidian reports the error:

Vault not found.
Unable to find a vault for the URL obsidian://open?path=/path/to/testvault

Use Cases

Resolving this issue would drastically improve in a few scenarios. For reference, opening a (uncached) vault using the GUI takes 4 Steps:

  • Open obsidian
  • If there is a vault open pressing Open Folder as vault
  • Navigating to the vault on the file system
  • Opening it

This change would allow for automating this entire chain. You might create a script to open certain vaults for you automatically or reopen old (uncached) vaults.

Vaults might suddenly get removed from your vault list if Obsidian has been opened without the file location of the vault being accessible (Vault might be on a USB stick, a remote server, encrypted storage). For each time this happens, you need to redo the entire process above. Depending on file system depth, this can take a minute.

If you have a remote vault and your internet sucks, obsidian might auto close the vault every few minutes, forcing you to reopen.

Proposed solution

Allow obsidian://open?path=... to open a vault even if it has never been opened before by automatically registering it in obsidian.json.

Expand the URI functionality of the path attribute in the open action (obsidian://open?path=...) to allow for uncached / unopened vaults. Obsidian should check if a folder location / vault has not been recorded in the obsidian.json file. If so it should append it there and “discover” this new vault.

(I am not sure wether it should check if the folder location actually contains a .obsidian file. If the folder does not contain a .obisidian file, it may initialize a entirely new vault.)

The URI schema does not have to change for this.

Current workaround (optional)

Using a script to automatically edit the obsidian.json file. However the implementation is unstable since it breaks when e.g. the obsidian.json format changes. I have not personally tested this example code.

Related feature requests

In response to this old feature request.

I opened a new feature request because of:

1 Like

Workaround (not very pretty) is possible with CodeScript Toolkit.

If you have a vault (named Foo for this example) that has the plugin installed and enable corresponding setting:

obsidian://CodeScriptToolkit?vault=Foo&code=window.electron.ipcRenderer.sendSync('vault-open'%2C'C%3A%5Cpath%5Cto%5Cvault'%2Cfalse)

It’s not very readable, so I will split it in parts for clarity

obsidian://CodeScriptToolkit // protocol handler for plugin CodeScriptToolkit
?vault=Foo // name of the vault where CodeScriptToolkit plugin is installed and protocol handler is enabled
&code= // executing the code
window.electron.ipcRenderer.sendSync( // execute Electron command
'vault-open' // command to open vault by path
%2C // escaped comma
'C%3A%5Cpath%5Cto%5Cvault' // escaped C:\path\to\vault
%2C // escaped comma
false // whether to verify if the vault was already registered in Obsidian
)

Alternatively, you can do a similar thing using Obsidian CLI (doesn’t require CodeScript Toolkit plugin)

obsidian eval "code=window.electron.ipcRenderer.sendSync('vault-open', 'C:\\path\\to\\vault', false)"

Sadly, Command Line Interface to open folders (and files) in Obsidian from the terminal , was closed. Hopefully @WhiteNoise will consider reopening it and migrating my workarounds there.

1 Like