Obsidian Templater Scripts
- User scripts for Obsidian Templater Plugin.
Who is this for?
- Those who have some experience with the Templater community plugin and are looking for more basic and concrete API examples.
- For example, “I hear the Templater community plugin allows writing JavaScript in templates.
- This means I can call Obsidian’s API and do a lot.
- But I couldn’t get it to work. I’m not sure why.”
What is it for?
- Sharing useful features
- You will be able to use the
sakuraeditor_bookmark_like and insert_file features described below.
- Sharing know-how
- The Templater plugin is convenient because it allows you to call Obsidian’s API with JavaScript.
- You can do things similar to text editor macros.
- For example, like HideMaru Editor, text editor “Mery”, or Sakura Editor.
- It’s suitable when you want to quickly add functionality to Obsidian compared to community plugins.
- After trying it, I felt it would be easier if there were materials that could quickly demonstrate something like
Hello, World!.
- Therefore, I am publishing
templater_js_hot and insert_file below. I hope they will be of some reference.
What can it do?
sakuraeditor_bookmark_like
- What does it do?:
- Highlights the current line. It toggles the highlight.
- If text is selected, it behaves the same as Obsidian’s built-in “Toggle highlight” feature.
- Examples from other editors:
- Sakura Editor’s “Set/Clear Bookmark” (
CTRL + F2)
- HideMaru Editor’s “Mark Current Line”
sakuraeditor_abookmark_next
- Sakura Editor’s “Next Bookmark” (
F2)
sakuraeditor_abookmark_prev
- Sakura Editor’s “Previous Bookmark” (
SHIFT + F2)
insert_file
- What does it do?:
- Inserts the specified file at the current line (deletes the current line).
- What is it for?:
- For example, you can integrate it into your daily note template.
- For instance, you prepare a line like
Insert 8 PM tasks here, and at 8 PM, you click it. The line Insert 8 PM tasks here is deleted, and the prepared Templates file is inserted there. You can also use it to write Insert 9 PM tasks here at the end of that file.
- This is just one example. It’s assumed that there are more suitable uses depending on the user.
templater_js_hot
- This is a snippet-like feature.
- It’s a collection of small, self-contained code snippets, like
Hello, World!.
- They are commented out.
- Uncommenting each one will make it functional.
- I use it assigned to
CTRL + T.
- Both
sakuraeditor_bookmark_like and insert_file were developed using this.
- The advantage is low adoption and maintenance costs due to its small scale.
- The disadvantage is fewer development support features (compared to other large-scale development environments).
- It’s intended for initial adoption and writing small-scale scripts.
How to use it?
sakuraeditor_bookmark_like
- Templater
- Install the Templater community plugin in Obsidian.
- Folder
- Set the “Script files folder location” in Templater settings under “User Script Functions”.
- File Placement
- In the
Templates and TemplaterJS directories located under your vault,
- copy the contents of this repository’s
Templates and TemplaterJS directories.
- (These are Markdown and JavaScript files)
- Hotkey
- In the “Template Hotkeys” section of Templater settings, enter, for example,
Templates/sakuraeditor_bookmark_like.md.
- Click the nearby “+” button, open the hotkey settings, enter
sakura in the top-right field, confirm that “Templater: Insert Templates/sakuraeditor_bookmark_like.md” is displayed,
- click the “+” button on the right,
- and assign a key, for example, by pressing
CTRL + F2.
- Verify Operation
- Press
CTRL + F2 and confirm that the current line is highlighted.
- Press it again and confirm that the current line’s highlight disappears (toggles off).
sakuraeditor_abookmark_next
- For now, I’m holding off on using it.
- This is because it conflicts with Obsidian’s standard
F2 function (rename note).
- For now, I prioritize renaming notes.
sakuraeditor_abookmark_prev
- Setup
- Prerequisite: The steps for
sakuraeditor_bookmark_like must have been completed.
- Similarly, assign
sakuraeditor_bookmark_like_prev.md to SHIFT + F2.
- Verify Operation
- Press
SHIFT + F2 and confirm that it jumps to the highlighted line.
insert_file
- Setup
- Prerequisite: The steps for
sakuraeditor_bookmark_like must have been completed.
- Advanced URI
- Install the Advanced URI community plugin.
- Open the Advanced URI options screen and turn off all settings like
Open file on write. This is to ensure reliable operation verification. I use it with all settings off as is.
- Register Template command
- In the “Template Hotkeys” section of Templater settings, register the following two, for example:
Templates/insert_file.md
Templates/insert_fileを書く用テンプレ.md
- Verify Operation
- Type
insert_file in the command palette, or /insert_file as a slash command.
- Select
insert Templates/insert_fileを書く用テンプレ.md from the suggestions.
- Confirm that
[Insert test md (deletes current line)](obsidian://adv-uri?commandid=templater-obsidian:Templates/insert_file.md&insert-filename=Templates/insert_fileを書く用テンプレ用test.md) is inserted at the current line.
- Click it.
- Confirm that the current line becomes
This is the content of insert_fileを書く用テンプレ用test.md.
- Note
- The Shukuchi community plugin is convenient for quick keyboard-only use.
- It can be used as if “quickly pressing a convenient button with the keyboard”. I use this method daily.
templater_js_hot
- Setup
- Prerequisite: The steps for
sakuraeditor_bookmark_like must have been completed.
- Similarly, assign
Templater_js_hot.md to CTRL + T.
- Edit
- Edit
Templater_js_hot.js.
- Uncomment the
hello, world line.
- Verify Operation
- Press
CTRL + T and confirm that “Hello, World!” is inserted at the cursor’s location.
Reference Links