Command Line Interface to open files/folders in Obsidian from the terminal

You may be able to if you get a bit creative and are flexible. You seem to want to be able to open ad-hoc files. But Obsidian, like VS Code or JetBrains IDEs, is designed to work with workspaces, not isolated files.

So what you could do is pre-create a vault specifically for isolated files; let’s call it “Random”. Then we write a CLI script that when invoked on a file:

  1. walks up the directory tree and looks for an .obsidian directory. If none is found, then the file is considered outside a vault.
  2. If outside a vault, create a symlink to that file from inside the Random vault.
  3. Invoke the Obsidian URI with the Random vault as in above posts.
  4. Bonus: garbage collect older symlinks

I rapidly add and search Obsidian notes from the terminal using Fuz. It’s an extremely fast file fuzzy searcher, which I point to my Obsidian directory, opening files at selected lines.

The search results update instantly for every keypress, making it very low friction to add and search notes. While there is Markdown support, it doesn’t support e.g. images and linking like Obsidian does, so the two complement quite well.

1 Like

I too would like CLI links to obsidian files (+1)

My use case: I want to move my personal wiki (> 1000 entrances) from WikidPad to Obsidian. I don’t want to migrate in one go, but rather write new entries in Obsidian and move Wikidpad entries I’m updating. Wikidpad is still (and will be for years) the first stopping point when searching for notes. Therefore links from Wikidpad to new and updated entries in Obsidian would be useful.

Surprised no one mentioned the AdvancedURI plugin in this thread:

1 Like

Related is also: A terminal in obsidian

So, when you work with the terminal alongside with Obsidian, to perform other things Obsidian can’t do yet, it would be helpful to open files easily from the terminal.

It’s totally ok that Obsidian can’t handle everything. I don’t really need that Obsidian adds Git support, or whatever other support, when I just have a terminal. In any case, Obsidian will never support everything, so in any case I want to work with the terminal.

It seems Obsidian on Linux installed via AppImage does not recognize Terminal obs commands. I think because it is sandboxed, so the shell cannot see installation of Obsidian. Any way to resolve this or I need to install any other version of obsidian on Ubuntu debian?

I created a simple neovim plugin to open current file in its obsidian vault.
Here is the link to the plugin:

It builds an Obsidian URL of the current file and its vault, based on the git root subdirectory

1 Like

Hi, sorry I know this an old thread but this might be useful for others. I remember looking for an Obsidian CLI a week ago but couldn’t find anything useful although I found this thread. Anyway, I made something quick for myself and thought you guys might find it useful also, its quite simple but it does exactly what you want. Install and read instructions here:

Please let me know if you find any issues or have any suggestions!

3 Likes

I already did posted here my showcase, sorry for the repeated post ping.

lol why wasn’t done on day one? seems like an incredibly obvious requirement to be missing on day one release?

obsidian 
# launches gui vault picker

obsidian --help
# print all cli help

obsidian [vaultname]
# launches obsidian with [vaultname]

obsidian [vaultname] [path/to/filetype/that/vaultname/is/capable/of/opening]
# launches obsidian with [vaultname] and the file

I would like my software team to use obsidian to document their software designs within the git repositories containing their software. Among other benefits, this creates documentation that is always in sync with the branch being looked at.

Right now it seems that a vault can be opened by “name” if it has already been opened by Obsidian and is in its list of known vaults. We have a large number of repositories and navigating a large list of vaults or initially adding them via a gui is not desirable.

If my team could simply (for example) type “obsidian docs” from the root of a repository to open a vault residing in the “docs” subdirectory, it would be big improvement in convenience. For my purposes, I would not expect the vault to be added to the list of vaults that Obsidian remembers, but others might have different expectations there.

Thanks.

Something like this would really help me create and edit comprehensive README.md files on GitHub. A small, single-pane window would suffice. Please make this happen you incredible developers.

Thank you! It’s great to be able to open any note from Keypirinha. I’ve modified your callback function to work on files within subfolders, and with multiple vaults. This is the modified code:

# \Keypirinha\portable\Profile\Packages\FilesCatalog\filescatalog_user_callbacks.py

import keypirinha as kp
import os
from urllib.parse import quote

def obsidian_callback(entry, profile, plugin):
  """
  *entry* is a `_globex.GlobExEntry` object, which is an improved version of
  `os.DirEntry`.

  *profile* is a `namedtuple` defined in :file:`filescatalog.py` as
  ``ScanProfile``.

  *plugin* is the `FilesCatalog` plugin object itself.
  """

  if not profile.include_hidden and entry.is_hidden():
      return None
  if not profile.include_dirs and entry.is_dir():
      return None
  if not profile.include_files and not entry.is_dir():
      return None

  include = profile.filters_default
  for filter in profile.filters:
      if filter.match(entry):
          include = filter.inclusive
          break
  if not include:
      return None

  if entry.is_dir():
      item_label_tmpl = profile.dir_item_label
      item_desc_tmpl = profile.dir_item_desc
  else:
      item_label_tmpl = profile.file_item_label
      item_desc_tmpl = profile.file_item_desc

  formatter = _LazyItemLabelFormatter(entry, profile, plugin)
  item_label = formatter.format(item_label_tmpl, fallback=entry.name)
  item_desc = formatter.format(item_desc_tmpl, fallback="")

  encoded_path = quote(entry.path)

  return plugin.create_item(
      category=kp.ItemCategory.URL,
      label=item_label,
      short_desc=entry.path,
      target=f'obsidian://open?path={encoded_path}',
      args_hint=kp.ItemArgsHint.ACCEPTED,
      hit_hint=kp.ItemHitHint.KEEPALL)
2 Likes

Yes! Being able to invoke plugins with their parameters (e.g., expire tasks; export a page or vault) via the terminal, and consequently via scheduled scripts) would be fantastic.

Would you please add a command that allows me to cd into a directory and run obs . or something to open that directory as a vault?

I would love to have that option. I have several vaults and need always open different vaults. I like automation and want to automate it, open specific vault from cli. Obsidian is my loved software for taking notes. Why no such basic cli.

+1 FWIW

I’m amazed that this thread has been going for almost 3 1/2 years and there has been zero traction on it.

I followed @RasmusM’s instructions for Mac users above.
That worked like a charm. Never knew there was a “Copy Obsidian URL” in Obsidian mouse right click on a note!!! Fantastic!! Thank you!!

The magic that worked is:

// If you want a Note to open directly, use the full URL 
// you get from right-click and Copy Obsidian URL on 
// the Obsidian note. 
// Eg:

open "obsidian://open?vault=TheVaultName&file=TheNoteName"

// If you want to open the vault as is (last state, with your 
// last note that was working on, just use the vault from that
// URL constructed as mentioned above.
// Eg:

open "obsidian://open?vault=projects"

//Notice how the part after the '&' sign that is related to the 
// file name (aka the Note name) is now gone.

Just to add a bit more, the Mac open command can be used to
open a specific application URL or the application itself from the
command line.

// Following opens the application (-a option)

open -a obsidian

// Now the URL, to open the application and issue a command

open "obsidian://open?vault=projects&file=MyHubNote"

Enjoy!

3 Likes

Adding a use case here: opening Obsidian from a command would be awesome for automated tests on plugins. Developers would be able to further/better test their plugin and it would yield better plugin quality for everyone!

Use case not shared by any personal interest at all