Skip to content

Instantly share code, notes, and snippets.

@richkuz
Created May 18, 2023 13:21
Show Gist options
  • Save richkuz/a9afb437dc6cfcef3ba6590326256206 to your computer and use it in GitHub Desktop.
Save richkuz/a9afb437dc6cfcef3ba6590326256206 to your computer and use it in GitHub Desktop.
Obsidian: How to set the default title of a new note

How to set the default title of a new note in Obsidian

I wanted to set the default title of new notes created via Cmd+N to be formatted like "2023-05-18 New", "2023-05-18 New 2", ...

I also wanted all new notes created via Cmd+N to go in the new folder.

  1. Create a folder called e.g. new

  2. In "Files & Links" settings, set "Folder to create new notes in" to new

  3. Create a folder called e.g. templates and add a file called e.g. Default with this content:

<%*
for (let i = 1; i < 20; i++) {
	let suffix = i == 1 ? '' : ` ${i}`;
  // Replace with whatever format you want for your default note title
	let filename = `${tp.date.now("YYYY-MM-DD")} New${suffix}`;
	try {
		await tp.file.rename(filename);
		return;
	}
	catch (e) { // assume file already exists, try next filename
	}
}
-%>
  1. Install the Templater community plugin

  2. In Templater settings:

  • Set a templates folder location e.g. templates
  • Enable "Trigger Templater on new file creation"
  • Enable "Enable Folder Templates"
  • Add a new folder template for the folder new mapping to templates/Default.md

That's it! When you press Cmd+N, a new note will be created in the new folder with the filename pattern specified in the template code.

@colelawrence
Copy link

colelawrence commented Dec 15, 2023

Thanks for the guide. This is precisely what I wanted as well.

@scilear
Copy link

scilear commented Mar 25, 2024

even simpler <% tp.file.move("Notes/" + tp.file.creation_date("YYYYMMDDHHmmss Untitled")) %>
credit to https://forum.obsidian.md/t/templater-rename-a-file-and-move-it-to-a-folder/39287

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment