Hello. I'm a teacher. Every Sunday I duplicate the last week's plan, rename it and move the old file to an archive folder. Now I bought KeyboardMaestro yesterday so this may be a dumb question:
I made 3 macros: The first duplicates the original file, the second renames the duplicate and the third one moves the old file.
I set a given time as trigger: Sunday, 12:00. Now I'm wondering: What if the Mac is off or in sleep mode? Will it trigger as soon as I start it?
Is there probably a cleaner way to do this?
If you are worried about "missing a trigger" due to the computer being off (or asleep) then you need a solution that will check every time the computer reboots (or awakens) whether it missed an event. In order to do that, you need to record whether you conducted an event at the last time. Do you see why? I don't think any of the KM triggers store a record of their trigger times (or take action if they missed an event) so that means you will have to do manual event recording. There's nothing wrong with your request. It's entirely possible. Chances are good that it's already been done, so I won't write a solution before I search this website for an existing solution. But I really like your question and just for fun I'll probably write up my own solution. KM is very good at solving problems like this. Rather than triggering every Sunday at 12, it will probably trigger every minute of the day, check if it missed a backup, and execute the backup if one was missed.
Thank you for your detailed reply. I have some experience with Hazel but didn't upgrade to version 5 yet because I don't use it that much and just for doing this action I don't want to run another program. KM is very impressive but overwhelming.
I see the problem now and I understand the need for making a record. I'm searching the website but honestly I'm not sure what exactly I have to look at. I guess I lack the programmers way of thinking.
But I'm eager to learn.
If it checks every minute of the day if it missed a backup, wouldn't this put pressure on the system's resources like battery and RAM and CPU?
I love KM so far. I have it for a day now but I'm already autofilling dates into my Numbers sheets.
At the moment it's like going up a mountain and not seeing the top. I'm not sure if I can comprehend even a part of what it is possible to do.
Yes, KM is overwhelming. I've been using it (~)daily for 10(?) years and it still overwhelms me. I still feel like I'm working my way to its "base camp." You aren't alone!
I'm comfortable in saying a one-minute periodic check will NOT be a drain on system resources. Your operating system probably conducts thousands (or millions) of checks per minute, one more tiny check won't hurt anything. I perform some seriously heavy burdens on the CPU, and my M1 Mac Mini can tolerate it. For example, when I play computer games, I have an OCR engine running in a continual loop in the background and I can't even sense that it's running. And if you don't like it running every minute, then run it once per hour.
As I said I might write a solution for you myself, just for fun, even if it's already been solved. I like this kind of problem. But at this moment I'm making my lunch. There are different approaches to this kind of problem, and I'm trying to figure out which approach I want to take. Sometimes I go for the simplest approach, but sometimes I go for the most flexible, powerful, expandable approach.
I'll try to explain my usual workflow: Before every week I have to write a plan for my class. It's a combination of stuff I teach my students, the schools I have to drive to each day and my timetable.
1/3 of the document stays the same for the year, 1/3 changes every month and 1/3 of the document changes every week.
Usually I duplicate the file and rename it by hand. It's called "weekly plan_school week 11". The duplicate has the name "weekly plan_school week 11_copy". I rename it to the coming week: "weekly plan_school week 12".
Then I drag the old file into an archive folder so I always can return and look what we have done in a week.
Sure, I could copy the file into the archive and rename the original one but it would be the same, right?
Okay, I wrote a wonderful solution, but it has one feature that you didn't specify. That is, it makes sure that any macros you specify in its interface will be run as soon as 24 hours have passed since the last time it run. This is different from what you requested, (you wanted it to run as soon after 12:00 as possible) but at this point my macro is just for discussion purposes.
If you run the macro by pressing a hotkey, it pops up that question and you enter the name of a macro that you want to run every 24 hours. It also has a one minute periodic trigger to ensure that it's frequently checking whether it should run any of your macros.
I haven't had 24 hours to test it, so since it's untested, I'm going to post only a screenshot not a downloadable macro. If it works after 24 hours of testing I will probably upload the macro. At this point I'm uploading the image just so that we can discuss the requirements of the user's original problem.
At this point it works specifically with macros that need to run once per 24 hours. I'm pondering whether to extend it to support weekly, monthly, yearly, or some other time periods.
One thing I like about it is that it uses a KM Dictionary, which will give some people a good example of how and why to use dictionaries. I'm just not sure yet if adding support for other timeframes should be done with the same dictionary or with additional dictionaries. Probably the same one, but that would require additional code.
Thank you for all the details. I'm trying to decipher your post with the wiki, the helpfile and Google. I guess the learning curve is steeper than the Mount Everest.
At the moment I've found another flaw in my thinking:
The file is called something like "plan school week 11", 11 marking the 11th week of school during school year. It isn't enough to duplicate and rename the file, this will just work once. But then the rule isn't reflecting the coming school week anymore. So I have to get a math operation into the naming process. Like: "plan school week x+1", so that it adds a one to the actual week number. This makes me think that I first have to define that the 11 in the name is a number and not part of the name, right? This makes my mind explode.
My macro and my intentions were just to demonstrate in principle how to solve the problem of periodic macros missing a run even when the computer is off during an invocation time frame. I'm glad you are contemplating it for educational purposes. I wasn't really providing a solution to the part of your problem about keeping old versions of your file.
I'm not sure that your "intended solution" is the right solution. It's fairly common for people to go down a rabbit hole of a wrong solution. Now it's not illegal to go down rabbit holes, but most people are happier when they realize that their intended solution can be changed and improved upon. Basically, you just want a "versioning system" for your documents. I'm sure there are many products for macOS that do exactly that. But I'm not sure if any of that software is free. There very well might be some free versioning software for you. And if not, we can probably rig up something for you with KM. But to might not even include numbers in the file name, as you are currently envisioning.
As for your comment that the number is in the name - that can be handled by KM, if we need to go that way. But I'm not sure yet it's the right way.
MacOS does have software built-in called Time Machine which can do something almost identical to what you want. Have you considered it? I have a feeling you haven't considered it. Personally, I haven't used it yet, so I'd have to read up on it too.
Yes, I know. Thank you. Although it's just a demonstration of how to solve periodic macros it is very interesting and a good opportunity to learn.
I'm not sure if it's a good solution, either. But besides buying Hazel and doing it by hand it is the only one I see.
Time Machine isn't an alternative. I don't want to make incremental backups of one file. After this school year I will have an archive full of files containing what I've done with the kids. Next year I can jump back to any file and have a look: what have I done in school week 11 last year? Where have I been? Can I do something similar with new students again?
It's like a big log of files containing my work. I can also filter out single students and see where they had problems and all. Starting Time Machine to do this seems very inconvenient compared to opening an old file. And I like the idea that the files creation date reflects the date where I used the file.
I accept your decision about Time Machine. (I mentioned it because some people don't know about it.)
I respect your interest in a KM macro that makes automatic backups. This road hasn't been fully explored yet.
I don't think you considered version control software yet. These are usually intended for software developers but I suspect that most of them will work perfectly fine for people who edit files like you do. Most of them are free and most of them work with macOS.
I've an almost working macro (with the help of a very nice guy on Macpowerusers) that does what I want, there is just a problem with the naming. It deletes the number from the name instead of adding +1 to the number. Somewhere is a small mistake and I can't figure it out.
Thank you for the suggestion about version control software, but I guess this is something ultra next level. I looked into it and it would be like killing a fly with a Bazooka.
I had some time now, playing around... I tried to implement your solution... I tinkered around, played with KM and also Hazel. Now with Hazel I managed to implement a rule that does exactly what I want, but I guess this wouldn't be possible with KM because KM is trigger based, and Hazel is more like a if this... then that, right?
My rule in Hazel looks like this:
If it's Sunday and it is after 09:00 (or whatever time I set on Sunday) AND if the file wasn't added on this day, then do your folder magic.
But KMs trigger action is just available as "if this trigger OR that trigger". As much as I've found out, triggers aren't able to be set to AND actions. I can't define 2 trigger requirements that need each other to trigger, right?
Now, it would be easy to just throw the towel and pay my 20 bucks upgrade price for Hazel. The dev is nice and all. I like the app.
But I just don't need it (for now). And I do the exact same KM macro I've managed to get running here, with duplicating and all, with another set of files, but with a menu bar trigger because I don't need them to be duplicated and archived periodically but when I'm finished with the topic. This could be one or three weeks so there is no need for a periodical trigger. And this isn't what Hazel can do. Trigger actions. So I need the KM macro for this operation.
What I wanted to say: Is there a way to implement this if this, then that into KM?
Yes, it's possible to do all that in KM as well as Hazel. If you haven't seen it already, I suggest looking over the KM wiki page on the If Then Else action. Here's an example of how it would work with "Date is Sunday" and "time is after 9:00" conditions (the "file was not added today" condition, while certainly feasible, is less straightforward and requires extra steps involving variables, so I'm passing on those for now):
If we change the day of the week specified to "Monday", you can see how the condition becomes true, meaning the macro would run the actions included where the placeholder is now:
Oh wow... It's like... every time I think something can't be done in KM, it actually is possible... Awesome. Thank you so much. I see.
The "file was not added today" condition is not mandatory but I figured for Hazel that I would need some counter measure or it will copy every time it scans the folder. Like, it's Sunday from 9 am to 12 pm according to this rule.