Stationery (or [perhaps macros])

I’ll probably write a plugin like this eventually, but just dumping this here in case somebody else likes the idea and wants to do it first…

I would like to be able to have “stationery” in Obsidian. Not templates, but stationery.

What do I mean by that? Well, in the real world you can have pads or stacks of blank forms and grab one and use it immediately. In Obsidian, using a template generally requires multiple steps:

  • Creation of a new note (possibly in a new pane, possibly using Zettelkasten)
  • Issuing a template command of some kind
  • Selecting the template to apply (usually with lots of typing or else a mouse)
  • Optionally linking or embedding the new note in the old note

What I’d like to be able to do is set up commands that do all the above for a pre-specified template with a single hotkey (or at worst, a two-key sequence ala the Leader Hotkeys plugin). And I’d like to be able to do it with multiple templates, each with their own unique commands/hotkeys to insert, link, embed, or otherwise create the specified template as a note in a pre-programmed location with optional zettel numbering/dating.

The way I envision this is that I’d configure a “stationery drawer” (folder) in which the front matter of notes configures what hotkeys I want to use, what operations to perform, and optionally template the file path to create and set the target folder for notes using that note as stationery. The plugin’s settings would have defaults for those things.

On start, the plugin would scan the directory and register Obsidian commands with the appropriate hotkeys, and then update them after any changes (or perhaps have an “update stationery” command to do that with).

The front matter in a stationery note might look something like this, if all options were specified:

stationery:
  # commands
  create: Mod+J             # create new note, open for editing
  insert: Shift+Mod+J       # insert copy of template in current note
  link: Alt+J               # insert link to new note, create, open, and edit
  embed: Shift+Alt+J        # insert embed of new note, then create/open/edit

  # options
  newPane: true             # Should created notes be opened in a new pane?
  path: Inbox               # place created notes here
  file: "{{date:YYYYMMDDhhmm}} Jump List for "  # filename template

If one of the verbs was left out, a command wouldn’t be created; if true were used in place of a shortcut string, the command would be created but require using the command panel to access it.

The reason I want to do this is that I have a number of forms/prompts that I use for creative and other processes, and I would like to make use of them more often. Right now, Obsidian requires me to juggle a lot of mental steps around managing the state of panes and needing to click a bunch of stuff when what I really want is to get to filling out the form ASAP so I can capture an idea or work on a problem or whatever.

While I could probably implement something like this with some sort of macros, AutoHotkey is not really a solution at the moment because Obsidian dialogs are tricky to automate. It’s really easy to end up sending typeahead to a pane instead of to a dialog, so you end up corrupting your notes with the name of a template or whatever. (Also, a lot of the juggling required to keep track of the active pane, where the note is, what the name is, and all the rest of that is a major PITA to code in AHK’s puny scripting language.)

Of course, if Obsidian gets a macro system (or a plugin with a macro system), this use case should serve as a good example of what a sufficient macro system should be capable of: i.e. not just invoking commands but passing arguments to them, and doing things with the results.

There are possibly other ways to do some parts of this. For example, if there were a command to insert a zettelkasten-prefixed link into a note, leaving the cursor inside the link, you could type the rest of the title inside the link, then use Ctrl-Alt-Enter to open it in a new pane. If empty notes always offered you a choice of stationery to apply, the actions would reduce to:

  • Insert zettel link (possibly with leading !) and type any additional title
  • Ctrl-alt-enter and pick template

So I guess in the minimum case, my plugin would just provide a link generator command, and register a hook to trigger a template-insertion command when opening an empty note. The specific command could be either the built-in template plugin, or that of another plugin.

Since that’s way simpler than the original idea, I’ll probably do that first/instead. I’ll also see if I can add unique numbers, letters, or symbols to my stationery file names so I can select one with a couple of keystrokes.

Also, if I don’t need to link a note, I could possibly just use the Zettelkasten prefixer command to create the new note. And even if I did, I could probably just use drag and drop to the previous pane, since I normally pin panes anyway.

(I’ll still have to figure out how to tell if a file is “empty” in order to do the auto-insert thing, and it’ll probably need to switch to source mode before triggering the template command, since the templater doesn’t actually do anything if you run it in preview mode.)

Hm. Maybe I could make it even simpler, by making the same trigger that responds to focusing on an empty document also check if it’s “Untitled”, and then auto-rename it to have a Zettel prefix. Or trap the template insertion command so that inserting a template into an “Untitled” document applies a filename/location template using meta from the template. In such a case, all I’d need to do is Ctrl-N or Ctrl-Shfit-N to start a note, then pick the stationery and go.

Alright, I think I know what my next plugin project looks like. :wink:

7 Likes

Maybe I am missing something but isn’t this a workflow or macro?

Currently I am handling repetitive steps, key presses, etc with KeyboardMaestro and/or Obsidian keyboard shortcuts.

As I mentioned above:

I don’t know if Keyboard Maestro is better, but it’s Mac only and thus not of any help to me here.

Basically, for anything that takes a variable amount of time, pure keyboard macros are subject to timing issues that can end up corrupting data by typing it into the wrong pane or field in Obsidian. (And every Obsidian popup takes a variable amount of time to load, leaving the focus on the current document while they do so, allowing keyboard events to result in unwanted document changes.)

I ran into the same timing issue with Keyboard Maestro.

Solution was to insert a forced pause between troublesome steps.

It’s annoying to wait a second or two for the whole thing to complete but it does work, at least for KM. For AHK YMMV but I recall using pauses when I worked with it several years ago as well.

Hi everyone! Anything new in this regard since 6 month ago?

Many of the use cases I had in mind can now be met with the QuickAdd plugin:

It allows you to define macros in Obsidian, and make them commands (that can then have hotkeys assigned). It’s rather more tedious to configure than I’d prefer, but it gets the basic job done and is extensible with Javascript for advanced use cases.

1 Like