Automating Your Obsidian Workflow with Templater: Two Key Scripts to Organize Your Notes
Obsidian is already a solid note-taking app. But when you throw Templater into the mix, things get interesting. With Templater, you can automate repetitive tasks, saving you time and letting you focus on the actual writing. Two scripts, in particular, stand out for helping organize notes: one to create a folder index and another to gather all those indexes into a single list.
Why Automate?
Manually organizing a vault with hundreds of notes isn’t just tedious—it’s also prone to errors. Automating it frees up your mind to focus on more important tasks. With these two scripts, your notes will practically organize themselves, helping you maintain structure without the hassle.
Script 1: Generate a Folder Index
It's easy to get lost in a pile of notes, especially when they’re spread across multiple folders. This script solves that by generating an index of all notes within a folder and its subfolders, neatly organizing them in a hierarchical list.
The Challenge:
You’ve got a bunch of notes in a folder and need a way to view them all at a glance—without manually sorting through each one.
The Fix:
This script automatically generates a folder index, listing all notes alphabetically while indenting and grouping notes from subfolders.
Steps:
- Install Templater: Go to Settings > Community Plugins, search for Templater, and install it.
- Create a Template: Paste the script below into a new template file.
<%* function listNotesInFolder(folderPath, indentLevel) { const files = app.vault.getMarkdownFiles().filter(f => f.path.startsWith(folderPath)); const subfolders = new Set(files.map(f => f.path.slice(0, f.path.lastIndexOf('/')))); const sortedFiles = files.sort((a, b) => a.basename.localeCompare(b.basename)); sortedFiles.forEach(f => { if (f.path.startsWith(folderPath) && f.path.split('/').length - 1 === folderPath.split('/').length) { tR += `${' '.repeat(indentLevel * 2)}- [[${f.basename}]]\n`; } }); [...subfolders].sort().forEach(subfolder => { if (subfolder !== folderPath) { tR += `${' '.repeat(indentLevel * 2)}- **${subfolder.slice(folderPath.length + 1)}**\n`; listNotesInFolder(subfolder, indentLevel + 1); } }); } const folder = await tp.system.prompt("Enter the folder path to index (leave empty for vault root):") || "/"; tR += `## Index of Notes in ${folder === "/" ? "Vault Root" : folder}\n`; listNotesInFolder(folder, 0); %>
- Run the Script: Open a note, hit
Ctrl + P
(orCmd + P
on macOS), search for Templater: Insert Template, and select your new template. It’ll ask you for a folder path and will automatically generate the index.
What It Does:
- This script scans the folder and any subfolders for notes.
- Notes are sorted alphabetically and indented based on folder structure.
Here’s an example of what the output looks like:
## Index of Notes in Project - [[Note1]] - **Subfolder1** - [[Subfolder1_Note1]] - [[Subfolder1_Note2]] - **Subfolder2** - [[Subfolder2_Note1]] - **NestedFolder** - [[NestedFolder_Note1]]
Script 2: Group All Folder Indexes
After using the first script, you might want to compile all those indexes into one big list. This second script finds all notes containing the word "Index" and organizes them by folder.
The Challenge:
You have multiple folder indexes scattered throughout your vault, and now you need a master list that pulls them together.
The Fix:
This script scans your vault for "Index" notes and groups them into a clean, easy-to-read format.
Steps:
- Create a New Template: Copy the following script into a new template.
<%* const allFiles = app.vault.getMarkdownFiles(); const indexFiles = allFiles.filter(f => f.basename.toLowerCase().includes("index")); if (indexFiles.length === 0) { tR += "No notes containing 'Index' were found.\n"; } else { const sortedIndexFiles = indexFiles.sort((a, b) => a.path.localeCompare(b.path)); let currentFolder = ''; sortedIndexFiles.forEach(file => { const folder = file.path.substring(0, file.path.lastIndexOf('/')) || '/'; if (folder !== currentFolder) { currentFolder = folder; tR += `\n- **${folder === '/' ? 'Root Folder' : folder}**\n`; } tR += ` - [[${file.basename}]]\n`; }); } %>
- Run the Script: Same as the first one, run the Templater: Insert Template command and select your new script. It’ll search your vault for all "Index" notes and group them.
What It Does:
- It finds all notes with "Index" in their name and organizes them by folder.
- It outputs a clean list of all your folder indexes.
Here’s an example of the output:
- **Root Folder** - [[RootIndex]] - **Subfolder1** - [[ProjectIndex]] - [[TasksIndex]] - **Subfolder2** - [[ReportsIndex]]
The Benefits of Automating Note Organization
These two scripts aren’t just about making your life easier—they also help you stay focused on the important stuff. Instead of spending time manually organizing folders or tracking down notes, you can use automation to handle the busy work.
By creating folder indexes and pulling them together into a master list, you’re simplifying how you manage your notes. And once it’s set up, it runs itself. You don’t have to worry about forgetting to update indexes or manually sorting through files anymore.
The Power of Automation
Automation isn’t just about saving time. It’s about freeing up your mind. When you automate note organization, you’re removing the friction of managing a growing vault. It gives you more space to think about ideas, not logistics. And in the long run, that’s what matters. By letting tools like Templater do the heavy lifting, you can focus on what you care about—writing, thinking, and creating.
With these scripts in place, you’ll have a system that keeps itself organized. And once it’s running smoothly, you can focus on the actual content, which is the point of all this in the first place.