Using Obsidian Linter plugin to update YAML modified date

I’ve written twice in the blog about keeping the modification date (mdate:) in the YAML frontmatter of my Obsidian notes up to date. I no longer use either of those methods. Instead, I use the Linter plugin, which handles this inside Obsidian.

The earlier approaches

In November 2022, I described using fswatch to update note metadata. A shell script watched the vault for filesystem changes, read each changed note’s modification time with stat, and used sed to write that value into its YAML frontmatter. The script also had to filter out temporary files and unrelated events, and it needed to keep running in the background as a launchd user agent.

By May 2023, I was using a Hazel rule to trigger a similar shell script. In my discussion of file creation dates, I discussed a complication: rewriting a note with sed -i changed its filesystem creation date. The workaround used GetFileInfo to save the original creation date and SetFile to restore it after updating the YAML. Those utilities required the Xcode command line tools.

Both approaches put the responsibility for maintaining Obsidian metadata in tools outside Obsidian. There is now a much simpler way to handle this.

Using Linter

In Linter’s settings, open the YAML tab and find YAML Timestamp. Enable Date Modified. To keep using the field from my earlier examples, set Date Modified Key to mdate. The format YYYY-MM-DD HH:mm matches those examples as well. See the YAML timestamp documentation for the available options.

Linter settings with Date Modified enabled, mdate as the YAML key, File system as the source of truth, and YYYY-MM-DD HH:mm as the format
Linter's Date Modified settings, configured to update the mdate field using the file system as the source of truth.

The timestamp rule needs to run for the value to update. You can run Linter manually, or enable Lint on save in its general settings to run it when you explicitly save a note. Linter also offers Update YAML Timestamp on File Contents Update for updating the timestamp after edits to the active note; select an interval rather than Never if you want that behavior. The instructions for running rules explain the available triggers.

For me, the main advantage is that the solution lives inside Obsidian. Beyond the Linter plugin itself, it requires no external resources: no filesystem watcher, Hazel rule, background shell script, or developer utilities. The configuration stays with the application where I write the notes, and there is considerably less to maintain.

Usually simpler is better.

If you have questions or comments, please get in touch via my contact page.