Time of Day Trigger Not Working - Macro to Backup Google Calendars

@peternlewis @JMichaelTX @ccstone @gglick @mrpasini
thank you all for your comments.

I found a solution using gmail snooze

basically, I want to backup my google calendar every week with the macro above.
I can't do it using a time trigger because I have no way of knowing if my computer will be asleep.

Solution: compose an email and attach a text file entitled 'google calendar backup' → send it once so it is in the inbox → once it is in the inbox, I snooze the email so that it is sent one week later → in one week when I receive the email I click on download file → when the file appears in my download folder it triggers a Hazel rule → the Hazel rule triggers the KBM macro above

It works fine and bypasses the computer asleep issue when exact time is not an issue.

I just don't understand how you can even consider using a time trigger if you don't know if your computer will be asleep or not.
If you want to use time triggers, it is a question of the pros and cons of never letting your computer sleep, assuming you have a SSD drive

Off the top of my head I can't think of a better solution, but if you're going to use a solution like this you can at least cut out the text file and Hazel rule parts. Just include a URL link to run the macro in your email and click on that when you get the email.

You could also do something similar if you use a to-do app like Things or OmniFocus; just set up a task that repeats once a week, include the URL to the macro in the note field, and click that when you go to mark the task complete for that week to run the macro.

1 Like

thank you. It's a good idea. I am going crazy trying to figure out the macro's name or UUID to implement you excellent solution. I tried UUID extraction macros from the library but they do not work. I tried to display the UUID token but it does not work either.
Funny that there is not a 'right click' → copy UUID, like one would have right click → copy link

You're welcome. There may not be a right click to get a macro's UUID (though there is a menu option for it under Edit > Copy as > Copy UUID) but there is a much easier way to get the URL for running a macro than what you've been trying:

Jun-26-2019%2017-18-07

1 Like

you are fantastic !! great !! thanks for the effort in making a video. I am very grateful

1 Like

neither gmail nor apple mail recognize the following as a functional link. I tried both a simple paste and also paste into create link.
this is the link I used
kmtrigger://macro=2ED527D3-3E53-4322-8196-6CCB1D94F02D

The link in itself is fine because it works in Evernote (clickable, functional)

Hmm. True, Gmail doesn't seem to recognize it even when pasted with a link, but Apple Mail (at least on Mojave 10.14.5) seems to recognize it fine:

43%20PM

As does my email client of choice, Spark:

44%20PM

1 Like

yes, thank you. There was a glitch and now works with apple mail.

If there's no hoop, you can't jump through it. How about setting the backup to run either 1) on wake with the Wake Trigger (if it's quick) or 2) on sleep with the Sleep Trigger?

BTW, MacScripter has a nice summary of what you can and can't do (like schedule more than one pair of wake/sleep schedules) using pmset in a script.

1 Like

I thought about that : trigger when wake one day a week, and I then realized that since my computer wakes from sleep many times a day (since screen and computer sleep sync), I would end up with 20 backups that day.
thank you for your comment and the link

Thanks for jogging my mind, @mrpasini; I knew there was a better way to do this. See how this works for you, @ronald:

Backup GCal Once Weekly on System Wake.kmmacros (7.6 KB)
image

3 Likes

“Turn display off” only puts your computer to sleep if the following checkbox:

is off. Otherwise it only turns your display off.

That's how I run my Mac since it is backed up in the middle of the night, and performs other task.

An alternative way of using “timed” triggers is to use periodic triggers and have them operate only one per day and only if the Mac is sufficiently idle (there are examples of these on the forum).

1 Like

yes, Peter I am aware of that.

1- if you suggest never allowing the Mac to sleep, it‘s fine, and a great solution, but in the same vein, I think that you should address the issue of it being damaging to an iMac or not, assuming you only have SSD drives (which I do) ? Forums are very contradictory on that topic. If it‘s not damaging, I will click on Prevent from sleeping subito presto and leave it checked.

2- everyone including you seem to suggest that waking up the Mac is a problem, a limitation of the current MAC OS itself. For the sake of discussion, let‘s ignore the energy saver - schedule option which allows the user to schedule only one event at one time (single or repetitive). If that is so, why does carbon copy cloner automatically backup my Mac at night when it is definitely sleeping and in system preferences ‚prevent computer from sleeping is UNchecked ? This includes multiple backups of different items on my computer at multiple different times.

Your macro is fantastic !
I changed DAY() to 5 (today Thursday), put the computer to sleep, woke it up and the calendar was downloaded. I tried a second time and nothing happened which is perfect.
It took me a bit of time to follow the logic. I am using your macros to improve my understanding of KBM.
I prefer your method to playing around with the power settings. It is a brilliant approach to circumventing the power issue.
It is definitely the way I will go to backup my calendar.
I left the moving of the downloaded calendars to a dropbox backup folder to Hazel, because it is so simple.
I am also always fond of your use of if then else, ie thinking in algorithmic terms.
Thanks again very very much.

1 Like

I cannot say whether there are any consequences to having the Mac never sleep.

I can say I have run my desktop Mac this way for decades, with a Mac Pro, then an iMac, and now another iMac. The previous two had fusion drives, this one has an SSD. I have no idea if there are consequences to the SSD or any other component of the Mac.

No idea. Maybe like @mrpasini/@gglick suggest it waits for a wake (maybe a PowerNap wake) and then starts its actions.

1 Like

thank you Peter.

@mrpasini @peternlewis @gglick @ccstone @JMichaelTX

Hello,

I wrote to the developer of CCC Mike Bombich who by the way seems to be a very nice person, explaining that we are having a discussion in the KBM forum about sleep, wake and scheduling actions (tasks, triggers, etc) and the fact that CCC performs backups at night when the computer is asleep.

I am copy pasting his answer after having obtained his permission.

In my question, I summarized the different opinions above.

His complete answer is pasted below.


I'm happy to settle the debate :slight_smile:

In this case, you're all correct to some degree. Applications themselves cannot wake a sleeping Mac, only the System Management Chip on the motherboard can wake the system. However, any application may schedule a wake event with the SMC controller. There's nothing proprietary in that request, there is a standard system interface that we use, for example:

#include <IOKit/pwr_mgt/IOPMLib.h>

IOPMSchedulePowerEvent(wakeTime, BUNDLE_IDENTIFIER, CFSTR(kIOPMAutoWake));
IOPMSchedulePowerEvent(wakeTime, BUNDLE_IDENTIFIER, CFSTR(kIOPMAutoWakeOrPowerOn));

CCC schedules a wake event any time you schedule a task that is configured to wake the system at the scheduled run time.

CCC schedules a wake event with the system, and then when the system wakes at the scheduled run time, CCC runs the task. It's also worth noting, however, that macOS also has a ~2 hour "Dark Wake" cycle. Every two hours the system will wake from sleep automatically, and at that time background tasks have an opportunity to do work. If your CCC task's sleep handling is configured to "Run when the system next wakes", then CCC will not schedule a wake event, rather it will run during a Dark Wake cycle that happens to occur after the scheduled run time has elapsed.


6 Likes

Noted. I will look at it.

That said, I am not sure it is appropriate for Keyboard Maestro to just automatically wake up the Mac for a timed trigger. Keyboard Maestro has lots of other triggers, and they would not work either (periodic triggers, Idle trigger, MIDI trigger, Public Web, Remote trigger).

I'm not really sure it would be a good idea for me to have Keyboard Maestro attempt to wake up for all of these triggers.

Anyway, it is something to look at in the future.

2 Likes

@mrpasini @peternlewis @gglick @ccstone @JMichaelTX
@gglick 's astute macro works very well.
It's interesting that it was triggered not first thing in the morning when I woke up the computer, but during the night at the time of the CCC backup, because as discussed above CCC wakes the computer up before the backup.
This made me realize that the solution to my question was staring at me as this time: I could just schedule a bogus CCC backup any time I want to wake the computer before a KBM specific time critical time triggered macro.
That being said, for the specific purpose of backing up the calendar which is not time critical, I find Gabe's solution more elegant and will use it.

2 Likes