Create a Trigger for the First System Wakeup of the Day?

Hi everbody,

I'm a new Keyboard Maestro user and an AppleScript novice. Here's the automation I want to create:

When I wake up my computer for the first time each day, I want the application Day One to launch and go full-screen. The huge challenge is finding the right criteria to make "first wake of the day" a trigger.

If that specific trigger isn't possible, then maybe it's a trigger of "waking computer between 6 and 8 AM." Or maybe Keyboard Maestro can open Day One in the middle of the night, such that the app is waiting for me when I get to my computer the next morning.

Any ideas? I feel like an Applescript script is the solution...

Thanks so much,

That is easily done using the DAY() (day of the month) function. Simply remember the day of the last time you really did something, and if it is different, then its a new day.

So basically:

  • Trigger on Wake
  • If calculation “Last Wake Day != DAY()”
    • Lauch Day One etc
  • Set Variable “Last Wake Day” to calculation DAY()

Note that when you write that calculation “Last Wake Day != DAY()” it will show up in red because the variable “Last Wake Day” has no value, so the calculation is invalid. You can fix this by setting the variable to a valid numeric value in the Keyboard Maestro preferences, or by "Try"ing the last action to set it to today’s value. Or you can just let the macro run - the first wake will set the variable value to today, and then the macro will start working tomorrow.

This is a standard trick you can use to have macros that run on certain days of the week, month, year as required after being triggered by some other trigger that happens more frequently.


I have a related question. I implemented this same logic a while back, but wasn’t sure of the best trigger. I believe I tested the Wake trigger, but it didn’t work.

I have my iMac set up to never truly sleep. In the Energy settings I have it set up to allow the display to turn off (and the screen to lock), but never to actually sleep.

In this instance, what would be the best trigger to use? Currently I’m using “Periodically while logged in” with a set interval between 2 times. But this isn’t really ideal.

That's because your Mac was never asleep, so it cannot "wake" :wink:

I just curious: what don't you want to allow it to sleep?

See Triggers (KM Wiki).

Is there some activity, some app that you always do first thing, when you'd like the macro to trigger? IOW, since you are NOT waking your Mac, what event would you like to use to trigger the macro?

I have two macros I use every day: (1) On Wake; (2) Sleep.

#1 works for me because my mac was asleep.

But, of course, #2 I have to trigger manually. I have found that Trigger Macro by Name action (KM Wiki) works well for me. I just press the "Trigger by Name" hotkey, and then type "sleep" (actually just "sle" works), and RETURN. You could do the same with "wake", or whatever keyword works for you.

My KM approach is to NOT use a hotkey unless it is something I need to do several times a day. I use Trigger by Name for everything else.

BTW, KM offers a native Trigger by Name Action, which you can put into a Macro. OR, you can use the great macro by @DanThomas that works in a similar manner, but searches ONLY on characters in the macro name:

MACRO: Execute Macro by Name (Spotlight)


I can try allowing the machine to actually sleep again - it’s always ended poorly for me in terms of the wake-up experience as things catch up. I believe I first stopped allowing sleep when I had some applications that needed to be available at all times, those are offloaded to a separate machine now though.

If not, there are a few Macros I use very often, I can piggy back on one of those to trigger once per day maybe.

Trigger Macro by Name is useful for exactly the reason you mention, but I haven’t got in to the habit of using it yet. Definitely will try to get in the habit of using it.

Thanks for your help.

I'm sorry, I don't quite get it because I don't use a whole lot of these kinds of triggers, would you be able to show me what this would look like in pictures?

Here are the actions.

Keyboard Maestro Actions.kmactions (1.5 KB)


Keyboard Maestro documentation say Mac has to be away for it to run, is this not true?

You meant "awake" not "away".

Yes you are correct. The question in this thread was how do you get KM to trigger an action when it wakes up (for some other reason). The question wasn't about getting KM to wake up the computer, but to trigger a certain action when it wakes up for some reason. Is this explanation clear?

If you are asking whether it's possible for KM to wake up a computer, most people would say no, but there kinda is a way. If you want to know, I can explain.

Yes, please do. See the image below I want to be able to have

  1. Mac wakes up 6 AM (I can do this in preferences but...) (???)
  2. Caffeine turns on (This step works) using Applescript
  3. WSJ launches with Google (This step works)
  4. Caffeine turns off at 8:30 AM (???)


You can wake the computer using a setting in Preferences? That's exciting. Oh yes, now that you mention it, I found it. I didn't know you could do that. Thanks for the tip.

Since you can do that, you really don't need my method for scheduling a wake up. Both the Preferences Pane and my method are probably using the exact same underlying method. I just did it using a command line call which I called from KM.

I just found a web page which explains both the Preferences method and the command line method:

I presume both methods take advantage of the same Intel CPU clock features which support some kind of schedule wake up. There's no point in using KM to do it if you can use the Preferences Pane to do the same thing.

However my needs were trickier and I actually needed my KM app. That's because my computer was falling asleep without warning INSTANTLY about once per day. So what I did was wrote a KM script that ran every minute and set the automatic wakeup time to two minutes in the future. That way if my Mac ever fell asleep it would wake up again in about a minute.

My macro wouldn't have much use to you as it modified the wakeup time every minute, which is not what you want. But if you read the page above, you can figure out how to send a command using KM that will wake up your computer any way you see fit.

Mind you that method requires the sudo command which I think is a dangerous command because I think it requires an admin password in a batch file which is generally not a good idea. So there's another reason to avoid my solution.

is there a way to add another timer trigger so that it turns off caffeine after 2.5 hours?

There must be lots of ways to do that. I'm not sure which way is best for you. I'll look at your code above and try to come up with a way that feels compatible with your approach.

What would be wrong with adding these two statements at the end of your macro? Your macro will be in pause mode for 2.5 hours then at the end should turn the device off:

Use a CRON trigger for the desired action. For example, any action triggered by a CRON set as 0 7 * * * happens at 07:00 everyday.

Thanks for your help! below is how it ended. Not sure if it works yet.

There are many possible solutions to your problem. I thought this one would be best for you. If there's something you don't like about this one, we can find another.

Still can't get the Macro bellow to fully function. During the morning routine it only opens the Gmail URL but not the other two. Any ideas as to what to do to fix this?

I even added time delays.

I think you have to insert an action called "New Google Chrome Tab" between each "Set Google Chrome URL". I'm guessing because I don't really use KM with browsers.

And I leave on a vacation tomorrow so I may not be able to help you for a while now.

Thank you. I don't mean to sound so needy. I just love what KM can do. I do think it is weird that my Macro opens the Gmail URL but not the others, only because if you look at my Macro the Gmail URL is is 2nd in the order of 3 URLs.