One-click PDF files opening in default system app

Use case or problem

In my workflow, I have to open and annotate many documents such as Word, Excel and PDF files. When left-clicking on Office files in the File Explorer, they usually open right away in their default app. However, PDF files don’t open in Preview (Mac) but rather in what seems like an embedded web version of a PDF reader.

Proposed solution

The solution is right-clicking on the document and choose “Open in default app” but I feel like this is an extra step that could be simplified by creating a new setting such as “Always open PDF files in default app”.

12 Likes

+1
Want that too

I would love this. If I want to see it in obsidian I can always embed but opening outside has a ton of friction right now.

Would also really appreciate having an option to set this behavior as default.

I like this idea

I would love for this to actually be implemented properly. In the meantime, my crummy solution is to use Obsidian Shell Commands and Obsidian Advanced URI plugins.

In Shell Commands, add the following command

if [[ {{file_extension:no-dot}} == "pdf" ]]; then
var={{file_path:absolute}}
open "obsidian://advanced-uri?vault=Ext%20Brain&commandid=app%253Ago-back"  #got this from advanced uri command "Copy URI for command" selected "No File" then "Navigate Back"
open $var
fi

Be sure to replace the advanced URI link with your own vault name.

Hit “Events” for that command, and activate “Switching the active pane”

This is a zsh script running on macOS; for other operating systems replace open with whatever equivalent.

It’s a simple script, it just goes back to your original note and opens the pdf with the system viewer.

A more sophisticated & correct way to do it would be making an extension and hijacking the mouse click event.

if [[ {{file_extension:no-dot}} == "pdf" ]]; then
var={{file_path:absolute}}
open "obsidian://advanced-uri?vault=Ext%20Brain&commandid=app%253Ago-back"  #got this from advanced uri command "Copy URI for command" selected "No File" then "Navigate Back"
open "obsidian://advanced-uri?vault=Ext%20Brain&eval=if%28app.workspace.getActiveFile%28%29.extension%3D%3D'pdf'%29%7Bapp.workspace.activeLeaf.tabHeaderCloseEl.click%28%29%7D"
open $var
fi

Updated it so it’ll close the pdf if there’s no note to navigate back to. Note you’ll have to enable “Allow executing arbitrary code via eval” in Advanced URI plugin settings.

SIKE I made a real extension that does this.
Here ya go GitHub - aidan-gibson/obsidian-opener: Opens pdfs with default system app and opens md in new/existing tabs.

3 Likes