Templater
Templater copied to clipboard
"FileName.md has been modified externally" message after updating frontmatter via tp.hooks.on_all_templates_executed
Plugin information (please complete the following information):
- OS: Windows 10
- Templater version: 2.2.3
- Obsidian version: 1.5.8
- Templater settings: default
Describe the bug
When using tp.hooks.on_all_templates_executed
to modify the frontmatter via app.fileManager.processFrontMatter
, a message pops up "FileName.md has been modified externally, merging changes automatically.
This only happens when other text is inserted within the same template. If the template only executes the hooks, no message is displayed
Expected behavior No message should pop up
Screenshots
Image
Additional context
If a sufficiently long delay via await new Promise(resolve => setTimeout(resolve, 2000))
is added, then no message pops up. However, if the file is edited after the template is inserted but before the frontmatter updates, the message comes back.
I'm guessing this is because the file in the editor hasn't been saved to the disk yet, but I'm not certain.
template files used: template - no message.md template - popup message.md
asd
<%*
tp.hooks.on_all_templates_executed(async () => {
const file = tp.file.find_tfile(tp.file.path(true));
await app.fileManager.processFrontMatter(file, (frontmatter) => {
frontmatter["key"] = Math.random();
});
});
%>
I wonder if there is a way to tell obsidian to commit the changes to the file to the disk or cache or whatever it is immediately after inserting, rather than waiting for the few seconds where it will do so automatically