Changing the file creation date on macOS
If you modify a file in-place using sed
with the -i
option, you will get a file that has a new file creation date. On macOS 13.3.1, this is absolutely 100% true, although you will read claims otherwise. I ran into this problem while implementing a Hazel rule that updates YAML automatically in my Obsidian notes.
Background
I have use YAML frontmatter in my Obsidian notes. It looks like:
---
uid: 20221120152124
aliases: [20221120152124, AllAboutShell]
cdate: 2022-11-20 15:21
mdate: 2023-05-18 05:14
type: zettel
---
My goal is to update the mdate
field whenever the file changes. Hazel is the perfect tool for this, so I set about writing a rule that covers this case. The heart of the rule is a shell script action that writes the modification date: