I have a template, and idealy i woul prefer if i didn’t need to open file first, and could
apply it on a file using a right click menu.
<%* tR = "" -%><%*
const allowedVaults = ["Storage", "Flower Tree", "Abitest", "Archivist", "Attributes", "Akashi"];
const LEVELS_DOWN = tp.frontmatter.LEVELS_DOWN ?? 1; // Change this to move N levels down
const TERMINATE_IF_NOT_ENOUGH = false; // true = stop if not enough levels, false = go as far as possible
const fullPath = tp.file.path(); // full path including all folders
const parts = fullPath.split("/");
// Skip the first folder (current vault)
const foldersAfterCurrent = parts.slice(1);
// Find all valid vaults after current vault
const validVaults = foldersAfterCurrent.filter(f => allowedVaults.includes(f));
let targetVault, filePath;
if (validVaults.length < LEVELS_DOWN) {
if (TERMINATE_IF_NOT_ENOUGH) {
new Notice(`Not enough valid vaults to move ${LEVELS_DOWN} levels down.`);
return;
} else if (validVaults.length === 0) {
new Notice("No valid vaults found in path. Cannot move down.");
return;
} else {
targetVault = validVaults[validVaults.length - 1];
}
} else {
targetVault = validVaults[LEVELS_DOWN - 1];
}
// Everything after the target vault in the path
const targetIndex = foldersAfterCurrent.indexOf(targetVault);
filePath = foldersAfterCurrent.slice(targetIndex + 1).join("/");
// Open note in target vault
const uri = `obsidian://open?vault=${encodeURIComponent(targetVault)}&file=${encodeURIComponent(filePath)}`;
window.open(uri);
%>
Template, even if you probably don’t need it.
Things I have tried
I have looked into (With varius detai):
Quick add, note toolbar, Advanced URI, Commander, URI commands, Custom commands
and searches for “Menu” “Command” “URI” “Template” in the plugin marketplace
As well as ask AI with more or less, zero results.
I am starting to feel there is no, sensible way of doing it, but maybe i am wrong?
That shell command (in red) can access file specific information using the {{event_file_path}} variable.
The last part of executing Templater using command line is still missing though. You could instruct Templater using Advanced URI but this requires simulating the file opening and then closing it. There is openmode=silent but I’m not sure does it work (https://publish.obsidian.md/advanced-uri-doc/Concepts/Navigation+Parameters).
Here is the “replace templates in the active file” command uri: