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”.
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.