I’m working on a macro that helps me take a short break from my MacBook. For example, I want it to stop me from using the computer between 8:00 AM and 8:30 AM. Even if I try to log in during that time, it should lock the screen again.
This is just one part of the plan—I have more rules that will fully block me from using the computer.
But I’m a bit worried I might accidentally lock myself out completely. Is there a way to turn off KM if I restart the Mac or do something similar?
Yes, there are ways to turn off KM if you restart a Mac, but how would that help? If you wanted to bypass the macro that locks your Mac, you could just use the bypass mechanism. And then you've broken your own rule.
This being the case, there is NOTHING we can do that can actually stop you from using your Mac during a time window, because you could bypass the restriction.
And what do you want the solution to do if you are using your Mac at 8:01am, but you have something important open? Do you want KM to pause and let you save your work? Or do you want an instant shutdown that could lose important data? If I give you time to save your work, you could use that time to keep using your Mac between 8:00 and 8:30.
I have a suspicion that you're doing this not to stop yourself, but to stop a family member. And the bypass you are requesting is a bypass that you would know how to use but your family member wouldn't. Is that the case?
Have you considered the built-in solution that macOS gives you called "Screen Time?" It's in System Preferences, and there's a category called Downtime that may suit your needs.