This is a really nifty idea, thank you!
With a lot of trial and error, I achieved to successfully make minor improvements:
- Markdown files in
.trash
or.obsidian
will still be opened with your chosen Text Editor instead of Obsidian (unsuccessfully) trying to open them. - When outside an Obsidian vault, you can select and open multiple files at once (the original script is only able to open one file at a time)
My solution is probably quite hacky and since most of it is trial & error plus googling, I am afraid I won’t be able to help out customizing this solution even further, but I thought I’d nevertheless share the small improvement I achieved. The same instructions as above from @idea.list apply, you only have to input the following two scripts instead.
#!/usr/bin/env osascript -l JavaScript
function run(input) {
const app = Application.currentApplication();
app.includeStandardAdditions = true;
const obsidianJsonFilePath = app.pathTo("home folder") + "/Library/Application Support/obsidian/obsidian.json";
const vaults = JSON.parse(app.read(obsidianJsonFilePath)).vaults;
let openInObsi = false;
const pathArray = input.toString().split(",");
const toOpen = [];
pathArray.forEach(filePath => {
const isFileInObsidianVault = Object.values(vaults).some(v => filePath.startsWith(v.path));
if (isFileInObsidianVault && !filePath.includes("/.")) { // second condition prevents the opening of files in .obsidian or .trash
toOpen.push("obsidian://open?path=" + encodeURIComponent(filePath));
openInObsi = true;
}
else toOpen.push(filePath);
});
return [openInObsi.toString(), ...toOpen];
}
if $1 ; then
open "$2"
else
open -a "Sublime Text" "${@:2}"
fi