Sleep After Completing Current Time Machine Backup

Wondering if anyone could suggest some ideas for something I want to do - being able to have my system sleep automatically after completing the current Time Machine backup.

I found an idea while searching about for it:

tmutil status|grep -c "Running = 1"

which returns 1 if TM is running, and 0 if not.

Could I create a global macro to run that every x minutes, and trigger the sleep command based on a 0 result, or is there a better way to do it?


Just double-checking here: do you need this because you don't want to enable Power Nap (found in the Energy Saver system setting/preference)?

Precisely, it's a legacy system, and I don't want it waking up on its own once I've given it a sleep command.

It's currently using sleep and wake scripts that disable time machine on sleep, and re-enable it 10 minutes after wake (TM has this stupid habit of attempting to run the instant the machine wakes), so I want to add another one that I can rely on to issue a sleep command (triggering the sleep script which will turn off TM) & put the system to sleep after it finishes its current (sometimes hour+ long) TM run.

Just pop a loop into your existing "Sleep" macro that pauses it until TM has finished. Something like:



Can that be done the other way around - executing the shell script to test for the answer, THEN running the pause step? My impression is that if I were to use it as per the screenshot in my existing On Sleep trigger, triggering sleep would always incur that pause, even if TM wasn't running.

I think I'd prefer to keep them as separate functions to be honest - my existing On Sleep which just disables TM, and a second "Sleep After" function which I would only use when I need to sleep the machine while TM is in progress, but don't NEED the machine to go to sleep at that moment. So if the outcome of the Sleep After function then triggers sleep, that should then trigger my (separate) On Sleep function, correct?

Yep -- "Until" always runs at least once (I just don't think it gets enough Forum love, plus balance of probabilities says TM is most likely running in your situation).

There are other ways to do "loop 0, 1, or more times", eg an infinite loop with a "Break" when your condition is met, but here's the "While" version:

Do it in whatever way makes sense to you. You could use the above as a separate macro which you run from your "main" with an "Execute Macro" step -- when "Asynchronously" is turned off (the default) your "main" would be blocked until TM had finished.

But it does seem to be all of a thing:

  1. Run macro
  2. Pause until TM completes, if running
  3. Disable TM
  4. Sleep I'm not sure what you gain by separating it out. Even if you wanted the nuclear option of "sleep without waiting" to be available I'd suggest the same macro but with a second trigger -- eg ⌃⌘S and ⌃⌥⌘S -- and if %TriggerValue% contains ⌥ you don't run the "Pause while..." loop.

1 Like

Hi Nige_S,

Sorry, I was distracted by time-sensitive stuff - thanks fo your suggestions and ideas on it. I'll get back to this in a few days.