In Microsoft Word, macros are stored in the normal.dotm file, and it’s important for book editors like me to back them up since we have dozens of them. (Also, a recent bug came along with an update that deleted some people’s macros, unfortunately.)
I’m hoping there’s a way for KM to notice when that file changes then have it make a copy of the file in another folder with a name that has the date and time in it. I’m seeing a trigger for when an item is added to a folder but not one for when a file changes, unless I’m missing this.
Can this be done in KM? If yes, how?
Thank you so much!
You can't use a "trigger" but you can "poll" the file by checking it once a minute, for example. You can tell if the file changes (perhaps by checking the file's modification date if the date changes, or) by computing the hash of the file using the macOS command called "md5." In either case, you need to save the value from the file an hour ago and compare it to the current value. If the values differ, then the file has changed and you can save a copy with a new name with the date. Easily done, in about KM actions:
KM Trigger: Each minute...
Calculate the MD5 hash of the file using the KM execute shell script action
Compare the hash to the last known value
If the values differ then (a) copy the file; (b) save the new hash
It could probably be done in a single KM action by placing the logic inside the shell script action.
Sounds like a job for Hazel.
@Airy Unfortunately, I’m not that advanced yet. Even with scripts, I have AI make them for me. I may still try to do what you’re suggesting, but it’ll take me a while.
@noisneil Yeah, I’ve been avoiding buying it, but I went ahead and bought it today. It did exactly what I needed it to do. Just stinks I paid $42 for that. Haha. Oh well. I’m sure I’ll find plenty of uses for it. Plus I won’t have to use Automator’s folder monitor anymore.
I’m seeing a trigger for when an item is added to a folder but not one for when a file changes, unless I’m missing this.
You have probably seen the Folder trigger. Have you actually tried it?
Yes, it only works when files are added or removed, but often what appears to be an in-place modification is actually a file replacement: The program reads the file, renames it, creates a new file with the old original name, and deletes the temporary copy.
I'm not saying this is the case with your .dotm file, but it's possible.
Yep. Hazel is one of those apps that you'll find uses for you didn't know you needed. And with its very particular set of skills, it can do certain things better than anything else. I hope you find it's worth the investment!