Automatically update last modified date in note

Thanks a lot!

Maybe you should post a topic about your plugin somewhere in the forum to advertise it :slight_smile:

I have a question, I had created and used the following Templater script based on this thread.

<%*
setTimeout(() => {
  app.fileManager.processFrontMatter(tp.config.target_file, frontmatter => {
	if (!frontmatter['created']){
		frontmatter['created'] = tp.file.creation_date('YYYY-MM-DD');
	}
	if (!frontmatter['modified']){
		frontmatter['modified'] = tp.file.last_modified_date('YYYY-MM-DD');
	} else {
		frontmatter['modified'] = tp.date.now('YYYY-MM-DD');
	}
	if (!frontmatter['tags']){
		frontmatter['tags'] = null;
	}
	if(!frontmatter['file_type']){
		frontmatter['file_type']=null;
	}
  });
}, 200) 
-%>

ļ¼ˆThis script creates some properties if they do not exist in the note, and for the created and modified properties, it either gets the date from the system or changes it to todayā€™s date.ļ¼‰
It worked fine until yesterday, but today I noticed that when I apply this script to a note where no properties exist, it outputs plain text without any ---, as shown below, and no properties are created.

created: 2024-02-15
modified: 2024-02-15
tags:  
file_type: 

For notes that have at least one property, I am still getting the expected behavior.
As far as I have tried, the script works correctly in Obsidian v1.5.4, and appears to have the above problem in Obsidian v1.5.5.
I have looked in Obsidianā€™s Changelog, but could not find anything that might be related. I have looked in Obsidianā€™s Changelog and could not find anything that might be related to this.
If anyone knows the cause, please let me know.

Iā€™m not using processFrontMatter in my templates, but it would be strange that it worked until 1.5.5

I canā€™t help fix this, but thought Iā€™d offer up a gem as a way to deal with your date stamping: Update time on edit plugin

1 Like

@iiz @gregp Apologies this did seem to get broken in the last update due to an internal refactor. I have a fix ready that will ship in the next build.

5 Likes

Iā€™m also hoping the app.fileManager.processFrontMatter function will never be changed as many many peopleā€™s workflow depend on it and regulars and other frequent posters keep mentioning this method for property updates.

Cheers

2 Likes

Good to hear it! I will wait for the update.

Thanks for the info! Iā€™ve recently started using properties, so Iā€™m using the above script for the purpose of adding properties to the original notes, but I may automate it in the future.

Thank you so much. We really appreciate it

For anyone coming from Google, thereā€™s now a plugin which does this all automatically and updates dynamically every time the note is modified. Search for " Last Modified Timestamp in Status Bar" in the community plugins.

obsidian://show-plugin?id=last-modified-timestamp-in-status-bar