Have Obsidian be the handler of .md files / Add ability to use Obsidian as a markdown editor on files outside vault (file association)

+1 from me as well, and I’m also surprised this isn’t already available out of the box. Seems like a massive lost opportunity.

3 Likes

This is a perfect workaround for now! Thank you very much!!
You managed a very clear and understandable instruction so it was easy to implement.
Thankyou! I now can open .md files from anywhere on my Mac and perform simple edits.
Only downside is, that the temp folder doesn’t get deleted automatically. But heck, I am willing to delete the folder manually once in a while to achieve global opening of .md files!
Great work!!

1 Like

Definitely put my vote down for that opportunity!

1 Like

+1 for request.

Obsidian must be open in order to make edits, so it doesn’t matter if Obsidian can or cannot open markdown files.

Obsidian stores files in an open “database”, so it knows where to search for all its markdown files

Maybe Obsidian could import / move outside markdown files but then, into which vault? The current one if a vault is open or yet another vault if Obsidian is closed and you’ve more vaults?

Obsidian handles files based on their open database concept called vault. It’s not about markdown but knowledge management inside an open database.

I just tried linking the file to my Obsidian vault (I think I saw that mentioned earlier) and I just did from Terminal (MacOS)
ln -s <source-file> <target-file>
where <source-file> is the original file
and <target-file> is the new Obsidian file name.
Seems to work just fine for me.

+1 for this.

Just re-release the editor only as a new app and charge $20 for it. Shoot iAWriter is charging 50 and the obsidian editor is much better.

For iOS this would be a huge win for the editor. Throw in the iOS commands for quick editing and allow a “template” folder somewhere and I’d gladly throw money at that app.

Would it be a scaled down version of markdown that opens files from Apple files on mobile…yep. Would not want this as a feature of obsidian directly as it’s a bit confusing, but calling it obsidian editor or something separate to clarify what it does and play off obsidian branding probably won’t hurt.

3 Likes

Use case or problem

When I set *.md files in gnome to open in obsidian, it simply doesn’t open that file. This includes markdown files that are within the vault (so the full path is known). If obsidian is already opened, it has different behavior by opening the launch screen, not even the open app.

GNOME version: 43.6
OS: Debian GNU/Linux 12 (bookworm)

Proposed solution

Open the markdown file in obsidian. (Particularly when the file is already within the vault).

Current workaround (optional)

Don’t associate obsidian as what markdown files open with

Related feature requests (optional)

Similar request:

1 Like

A standalone Obsidian markdown editor would be excellent, naysayers be damned. +1

4 Likes

uh since my request got merged into this one, I’m going to clarify that opening ANY markdown file even files within the vault folder… does not open that markdown file using GNOME. It just opens obsidian in whatever prior context it was regardless of the file selected.

simply opening a new tab of the markdown requested would be better behavior.

2 Likes

This is a very fascinating discussion. I think obsidian should eventually implement this natively, where if it can resolve the file to a vault, it opens the file within the vault, else it opens in a vault-less mode that allows editing or previewing of the individual file. Code editors like sublime and vscode have “project” views and “file” views, and are smart enough to display one or the other depending on what you open in them.

In obsidian’s defense, code editors generally allow you to configure plugins system wide (and thus they are available while editing individual files) whereas obsidian’s plugins are on a per-vault basis. Users with lots of plugins would get a severely limited experience when opening a vaultless file, since there is no global or default plugin configuration for obsidian to fall back to. This makes this request a unique user experience problem that doesn’t have a perfectly analogous solution that the obsidian developers can follow.

In the meantime: I really liked some of the above suggestions. On macOS a separate “markdown opener” application that could be used as the handler for all md files, or a quick action that could be used as an alternate to opening the markdown file seem like the next best solution. As others have stated the logic in either case would be (1) if the note is part of an obsidian vault, open with obsidian url handler or (2) open with a default editor if not

I figured out a way to create an application on macOS that can do exactly this, now when I double click a markdown file it will either open in obsidian or sublime text. Instructions for Sublime text below. If you wish to use another application (such as TextEdit), just replace the “Sublime Text” with the name of the text editor you want to use before saving your Automator application.

Instructions

  1. Open Automator:
    • Navigate to your Applications folder and open Automator.
  2. Create a New Application:
    • In Automator, choose to create a new Application.
  3. Add a Run Shell Script Action:
    • In the search bar at the top left, type “Run Shell Script” to find the action.
    • Drag the “Run Shell Script” action to the workflow area on the right.
  4. Configure the Shell Script Action:
    • In the “Run Shell Script” action, you’ll see a text area where you can write your bash script.
    • Set the Shell to /bin/bash.
    • Set Pass input to as arguments.
    • Copy and paste the below bash script into the text area provided.
# For each file that we are passed
for f in "$@"
do
    # start at the folder the file is in
    dir=$(dirname "$f")
    # while we are not at the root of the hard drive
    while [ "$dir" != "/" ]; do
        # check to see if we have reached an obsidian vault
        if [ -d "$dir/.obsidian" ]; then
            # If we have, open in obsidian
            open "obsidian://open?vault=$(basename "$dir")&file=${f#$dir/}"
            exit
        fi
        # go up one folder to se if we are in an obsidian vault
        dir=$(dirname "$dir")
    done
    # if we get this far, then we reached the root of the hard drive, and did not find an obsidian vault
    # Fallback to Sublime Text
    open -a "Sublime Text" "$f"
done
  1. Save the Automator Application:
    • Go to File > Save or press Command-S.
    • Save the Automator Application in your Applications folder with a suitable name (e.g., MarkdownHandler.app).
  2. Set the Automator Application as the Default Handler:
    • Find a .md file in Finder and right-click it.
    • Choose Get Info.
    • Expand the Open with: section.
    • Click the dropdown and choose Other....
    • Navigate to and select your Automator Application (MarkdownHandler.app).
    • Click Add.
    • Click Change All... to set this application as the default for all .md files.

Now, whenever you open a markdown file, it will be processed by the inline script in your Automator Application and opened in the file’s containing obsidian vault whenever possible, or your fallback application otherwise.

10 Likes

Fallback editors I’ve tested the above script with:

- Sublime Text
- TextEdit
- iA Writer
- Visual Studio Code
2 Likes

You sir, are the grand master! :raised_hands:
Works like a charm and I truly appreciate you sharing this.
I don’t know if something like this could be used by the developers of Obsidian to workaround the issues some people mentioned here. I’m not a developer myself, so whatever others were trying to explain on why Obsidian can’t open the .md files, goes over my head 100%.

Anyway, just wanted to thank you for sharing this :muscle:

The .md files now have a different icon based on the MarkdownHandler.app
image

I was able to change this by changing the .icns file inside the MarkdownHandler.app (Right click > Show Package Contents > Contents > Resources > AutomatorApplet.icns).
I delete that file and copied the one inside Obsidian.app and put it in that same Resources folder.
I kept the name “AutomatorApplet.icns” just in case, because I don’t know if that would make a difference or not.
And now all my files open using your script, and have the Obsidian icon:
image

image

:slight_smile:

2 Likes

There’s a feature request to rectify that here: Global Settings / Same settings, themes, and plugins across multiple vaults

Without that, or at least an option to choose a primary vault and use its settings and plugins, the ability to use Obsidian as a markdown editor for files system-wide would be almost pointless.

1 Like

Thank you! Thank you! Thank you!

I was looking for something exactly like this and I will promote it.

And it works with MarkEdit ( GitHub - MarkEdit-app/MarkEdit: Just like TextEdit on Mac but dedicated to Markdown. ) as well.

It works perfectly out-of-the-box on Windows 11. Thanks!

1 Like

oh, great!
We could probably make a mac OS shortcut out of it.
It would be even easier to set up: just a download link and install…

not sure I can make it myself, but I might give it a try in the next days…

1 Like

I think it might be possible to solve it this way.

First I’m assuming that all the features in Obsidian are modularized and that it’s relatively simple to set a feature to be enabled and disabled.

Next, the Vault configuration file could be placed in a fixed path, for example in My Documents, or in a path specified by the user.

Then, add a new entry point for Obsidian, such as “Open file in standalone mode”.

When starting Obsidian from this entry, Obsidian will quit reading the .obsidian folder in other directories, and instead read the contents from the path mentioned above.

At this point, Obsidian can disable all plugins and functions related to Vault features.

Next, it’s just a matter of reading and saving the specified markdown file.

I think this might be a simpler way to implement this.

Thank you a lot! That’s exactly what I wanted! It’s perfect and simple. :fire:

I’m on Linux. I use GitHub Desktop and git-cola (diffing my files).
I wanted to be able to quickly open the given file in Obsidian where I have tons of customized goodies for editing (Templater Js scripts, hotkey combos etc., while I don’t have those in other editors such as Sublime Text).

Enter obsidian-cli, which works on all platforms.
I’ll just put here a how-to on Linux, but it’s a similar setup for other platforms.

Add in your file manager the default markdown opener a shell file, which should contain (provided you installed with brew):

#!/bin/bash

# Full path to the obs command
OBS_COMMAND="/home/linuxbrew/.linuxbrew/bin/obs"

# Check if a filename is provided as an argument
if [ $# -eq 0 ]; then
    echo "Usage: $0 <markdown_file>"
    exit 1
fi

# Get the filename from the first argument
markdown_file="$1"

# Extract the note name from the full file path and remove the leading directory path and the ".md" extension
note_name=$(basename "$markdown_file" .md)

# Open the Markdown file in Obsidian
$OBS_COMMAND open "$note_name"
  • Save the file with .sh extension and make it executable (e.g. chmod +x open_markdown_in_obsidian.sh). You can put this file in a folder in your vault so it will be synced and not lost on a hard drive crash.

The experience is really good. The file opens faster than if I want to open a file inside Obsidian.
The cli has much more to give than just open files, of course. It’s an alternative to Obsidian URI.