Templater: Trigger Templater on new file creation

Thanks for all the answers and ideas. Based on all your input, I have found the solution to my questions. For people who could be puzzled with the same questions, I sum up the answers:

Is there a way to manually create a new file/note that is not empty? If so, how to tell Templater which template to execute on the new note?

My initial misconception was that a new file/note is always empty. This is a false assumption: in Obsidian context, “new” solely means that the file has been “seen” by Obsidian for the first time (as a note), so that an Obsidian “new file creation event” is generated. The file itself - from the file system’s view - could have been existed before it has been detected by Obsidian, e.g. if you moved an existing file with existing content into Obsidian vault’s folder.

What is the difference in Obsidian/Templater behavior if I solely toggled “Trigger Templater on new file creation”?

Since the “new” file could have some content, this content could contain some Templater commands. Activating the option “Trigger Templater on new file creation” causes Templater to listen to Obsidian vault’s event “create” and to evaluate the content of the “new” file as a Templater template.

This behavior can be verified by a simple experiment:

  1. Create a random Templater template file outside of your Obsidian vault.
  2. Enable the Templater option “Trigger Templater on new file creation”.
  3. Copy the template file into your Obsidian vault.
  4. Verify that the file has been processed by Templater as if you had had triggered the command “Templater: Replace templates in the active file”.
  5. Delete the file/note.
  6. Disable the Templater option “Trigger Templater on new file creation”.
  7. Copy or move the template file (from step 1) again into your Obsidian vault.
  8. Verify that the file has been left untouched by Templater.

This results in the known security warning, that I only now understand in its full scope:

If the option “Trigger Templater on new file creation” is activated, never blindly copy or move any MD files to your Obsidian vault! Also: never blindly change the extension of not MD files to MD files inside your Obsidian vault - that would trigger a “create” event as well and cause Templater to process the file’s content; if the file contains malicious Templater commands, you could get hacked.

1 Like