Executing scripts - chrisgurney/obsidian-note-toolbar GitHub Wiki

Note Toolbar supports items that execute [Dataview]], JavaScript ([built-in, or via JS Engine), and Templater queries, commands, expressions, and scripts.

[!tip] Need help with scripting? Start a Scripting discussion ↗, take a look at the examples folder ↗ or look at the resources linked from each of the script pages below.

Enable scripting

To get started, in Note Toolbar’s settings, toggle the Other → Scripting setting to ON. When creating new toolbar items, JavaScript will be added to the Item Type list, and any plugins (Dataview, JS Engine, and/or Templater) you have installed and enabled will appear as well.

Script item types

Assuming the corresponding plugins are installed and enabled, these item types will become available:

Each type has a number of functions to choose from, each of which behaves differently. Read further on for how output can be handled.

Where does output go?

Unless otherwise mentioned, if output is returned or rendered in the script (e.g., via Dataview’s dv.paragraph(), JS Engine’s engine.markdown.create()) it is:

  • inserted where the cursor is located; or
  • (optionally, depending on function selected) put in the provided Output callout.

Output callout

For those functions that accept a Output callout ID parameter:

  1. Create a note-toolbar-output callout somewhere in your note, and put the ID you want to use in the meta field, like so:
> [!note-toolbar-output|idgoeshere]

This is what an empty note-toolbar-output callout looks like in your note:

  1. Provide the ID (i.e., idgoeshere) in the Output callout ID field.

Then, on script execution:

  • The Output callout’s previous content is replaced with the script's output.
  • If the provided ID does not match a callout in the note, a message will be displayed.
  • ⚠️ In longer notes I believe the callout needs to be within view when using your button, in order for Note Toolbar to be able to find the callout, due to how Obsidian displays longer notes ↗.

Note that the content in these callouts is temporary, and may disappear after a time.

I may replace this feature with inserting content directly into the callout. I’d love feedback on this.

How are errors handled?

Errors with scripts are returned as results where possible (e.g., as a summary at the cursor, or in Output callouts), and/or reported to the development console.

Accessing toolbars from scripts

See the Note Toolbar API for methods to update individual toolbar items, or to show helpful UI such as suggesters and modals (including from Dataview and JS Engine scripts).


Learn more: DataviewJavaScriptJS EngineTemplater

Read next: Other settings