[Hack] Open Obsidian Templater from the Command Line, an iOS Shortcut, or a browser bookmark
Obsidian is an epic note taker. Unlock another dimension of it's productivity
If you’re not using Obsidian to take notes, it’s like the VS Code of notetaking tools. This article dives deep into how to unlock it’s power.
I'm on a mission to do one thing in Obsidian: have an iOS shortcut that can first open Obsidian and then run any command (such as Templater’s “Templater: Create New Note from Template” command). My goal is to make it as easy as possible to have an icon on the home screen of my phone that can instantly take me into running any command.
Running any Obsidian Command
Obsidian command pallete is like VS Code’s. This section teaches you how to open and run a command inside obsidian by first calling it from an external application.
Plugins I need:
"Advanced URI" plugin
"Dataviewjs" plugin
“Templater” plugin
First, we need to create the URI. To do that, we need the command ID. Here's a snippet that allows you to get a list of all internal commandid names so that you can call the command from a URI.
Just wrap this in a ```dataviewjs code block:
const getNestedObject = (nestedObj, pathArr) => {
return pathArr.reduce((obj, key) =>
(obj && obj[key] !== 'undefined') ? obj[key] : undefined, nestedObj);
}
function getHotkey(arr) {
return arr.hotkeys ? [[getNestedObject(arr.hotkeys, [0, 'modifiers'])],
[getNestedObject(arr.hotkeys, [0, 'key'])]].flat(2).join('+').replace('Mod', 'Ctrl') : '–';
}
let cmds = dv.array(Object.entries(app.commands.commands))
.sort(v => v[1].id, 'asc');
dv.paragraph(cmds.length + " commands currently enabled.<br><br>");
dv.table(["Command ID", "Name in current locale", "Hotkeys"],
cmds.map(v => [
v[1].id,
v[1].name,
getHotkey(v[1]),
])
);
Then to construct the URI, follow the Advanced URI schema:
# Schema
obsidian://advanced-uri?key1=value1
# commandid
templater-obsidian:create-new-note-from-template
Replace the colon :
with %253A
. Now get the full URI:
obsidian://advanced-uri?commandid=templater-obsidian%253Acreate-new-note-from-template
You can copy and run this in the browser and it’ll open Obsidian and act as if the command pallete has been invoked.
Reap the Power
Now with this URI you can put it wherever it’s useful:
You can bookmark this URI in Chrome to quickly open Obsidian from Chrome and create a new note from template.
On your iPhone, you can create a shortcut and use the "Open URL" command. Then you can use an app like FlowLock (no affiliation) to run this shortcut.
You can create a terminal alias to open obsidian from command line:
open "obsidian://advanced-uri?commandid=templater-obsidian%253Acreate-new-note-from-template"
Boom, now you can click a button on your Home Screen or a Bookmark in Chrome and have it run obsidian commands.
Troubleshooting
Two things I’ve found.
On my iOS, usually Obsidian has to re-open and load the vault. If Obsidian isn’t open and loaded, then the templater new note won’t pop up.
Bookmarks in Chrome will give you an annoying popup of "Open url in Obsidian?". To turn that off, run this in your terminal:
defaults write com.google.Chrome URLAllowlist -array-add 'obsidian://*'
How else can I use this?
Have it run the "templater:create new note from template" command. I have this URI bookmarked on Chrome as well as on my Home Screen.
Have it open a weekly note (reddit).