Hi, is KM running even if my machine is in "sleep"?
No, but with the correct techniques you can get your Mac to wake up at a specific time and then execute a macro. What exactly do you want to do?
P.S. When you said "my machine is in sleep" is there any chance you meant "my display's power is off"? That's a different question with a different answer.
what are the techniques, if I may ask? I'm new to KM and would like to know.
What you mean whether the macro can still be run when Mac is in sleep. My answer is no after having experience trying that. Action like periodic trigger will not run if Mac is sleeping. ChatGPT give the following answer and suggestion:
" No, Keyboard Maestro macros cannot run when your Mac is in sleep mode. When a Mac is asleep, most of its systems, including Keyboard Maestro and other software, are inactive. Sleep mode suspends tasks to conserve energy, and only certain low-level processes or hardware wake-up events (like network access if "Wake for Network Access" is enabled) can run during this state.
Workarounds:
- Prevent Sleep Mode: Use an app like Keyboard Maestro itself, or macOS settings, to prevent your Mac from sleeping while a macro needs to run:
- Go to System Settings > Displays > Advanced > Prevent your Mac from sleeping when the display is off.
- Alternatively, use a third-party app like Amphetamine to keep your Mac awake temporarily.
- Wake the Mac: Use scheduled wake-up settings to wake your Mac before running a macro:
- System Settings > Battery > Schedule: Set a schedule for your Mac to wake at a specific time.
- Combine this with a time-based Keyboard Maestro macro.
- Run Macros After Waking: Use a Keyboard Maestro macro trigger for when the system wakes up. For example:
- Set a macro with the “Wake” trigger to perform actions immediately after the Mac wakes up.
If you need automation that works even during sleep mode, you might need to explore external hardware solutions or wake-on-demand features, but this usually goes beyond standard software automation capabilities."
MacOS has the ability to wake up on a schedule. MacOS also has the ability to auto-login to an account. If you combine these things, you can get a KM macro to run when the Mac is off (by using those feature to turn it on) and then turn off or put the Mac to sleep afterwards.
For more information, read up on the macOS command called "pmset".
You can even get KM to issue the pmset command itself, rather than doing it manually.
If you need more explanation, I can elaborate later.
Thanks for all the replies. I got just busy. But yes, what I mean is sleep, not just the display's power is off.
This is because I'm wondering how Remote Trigger works. I read somewhere on this forum that it's "polling" its server. What I would like to do is to create a custom remote trigger if that's possible.
Did you read the following page? If so, what specific questions do you have?
https://wiki.keyboardmaestro.com/trigger/Remote
I don't see a connection between remote triggers and triggering while asleep. Maybe it would help if you explain why you want to use remote triggers. What are you trying to achieve?
If your Mac is asleep it won't do anything (Power Nap processes excepted, but they don't help here).
So don't let your Mac go to sleep... A Mac that's awake but idle and with the screen off uses very little power, so that shouldn't be an issue.
If you must sleep it you will need to go a route other than Remote Triggers -- you'll also have to accept that you probably won't be able to "send a command, macro runs" and will have to instead "check every n minutes to see if I should run a macro" where your trigger is the presence/absence of a file on iCloud or similar.
Sorry. Forgot to explain. So I want to wake my machine from sleep which is working using Wake Screen via remote trigger. Because of that, I'm wondering how it works since the machine is asleep. So I'm thinking if I can create my own custom trigger but before that, I need to make sure if KM is running when mac is asleep because I can do it via remote trigger while my mac is asleep.
You can't wake your Mac from a trigger running remotely. That's imaginative, but it won't work. Besides, "Wake Screen" wouldn't wake your Mac anyway.
That's easy. You can use pmset. Have you read up on this command? I think the following is the main thing you need to read:
SCHEDULED EVENT ARGUMENTS
pmset allows you to schedule system sleep, shutdown, wakeup and/or power on. "schedule" is for setting up one-time power events, and
"repeat" is for setting up daily/weekly power on and power off events. Note that you may only have one pair of repeating events
scheduled - a "power on" event and a "power off" event. For sleep cycling applications, pmset can schedule a "relative" wakeup or
poweron to occur in seconds from the end of system sleep/shutdown, but this event cannot be cancelled and is inherently imprecise.
type - one of sleep, wake, poweron, shutdown, wakeorpoweron
date/time - "MM/dd/yy HH:mm:ss" (in 24 hour format; must be in quotes)
time - HH:mm:ss
weekdays - a subset of MTWRFSU ("M" and "MTWRF" are valid strings)
owner - a string describing the person or program who is scheduling this one-time power event (optional)
If you also want to have your Mac automatically log in and then run a macro, this should be possible too. You would use System Settings to find the location to perform an auto-login when rebooting (which is NOT a safe idea in some environments) and then, if you also want to run a macro, you could use this trigger:
If this approach will meet your needs, give it a try and let us know if you get stuck. But if this will not meet your needs, tell us why.
P.S. There is also a way to use pmset to put your Mac to "sleep" and then you can use the KM Trigger called "At System Wake" which probably will also solve your problem. And it will be faster because it doesn't require a reboot.
Weird. I just tried it again and I can use "Wake Screen" macro to wake my mac mini from sleep and trigger it via remote trigger. I used this because I need to wake my device when I'm outside while its at sleep. I can't use schedule because I don't know when will I use it. It like I made it just for an "emergency" when I'm out and I need to control my mac
Maybe port forwarding with a trigger via the web server would work.
Right. I'm thinking that would work too but I can't do it right now since our router is a generic one from our internet provider and I can't configure port forwarding
Aha! Now I understand what you want. You have a computer that you want to wake while you are physically at a remote location. Got it.
I can think of three ways. There may be other ways.
- As long as your Mac is not a laptop, you can go into System Settings / Energy / Start up automatically after a power failure and make sure this is "ON" (it may already be on.) Then purchase a $20 power switch that looks like this: (I've seen them as low as $20.) You can then turn your Mac on remotely by restoring its power using the Apple Home app. If your Mac is using auto-login, then you can follow my advice in my previous posts.
- Get a "Fingerbot" (about $35) that will physically press a button, which you can easily trigger remotely, and it will turn on your Mac. It looks like this. Again, you will still need auto-login.
- When you say "when I'm out and I need to control my Mac", what exactly do you mean by "control"? Do you have a laptop with you and you are trying to run Apple Remote Desktop or Screen Sharing, and your laptop has VPN access to your home network? If so, I think you can solve this using "Wake Up On LAN" which most Macs support.
“Sleep” for a Mac these days is a very ambiguous term. There are a bunch of different levels of sleep, and the Mac will wake for various things and to deal with various things.
So it is possible that the remote trigger data sent from the trigger server to the Mac would be received even while the Mac is “asleep” to some degree.
Exactly what will and wont work when the Mac is sleeping is going to be very hard to predict. For example, a periodic trigger might trigger occasionally, but probably wont most of the time.
As noted, if you want your Mac to be able to take actions reliably then either:
- Turn off sleep (just sleep the monitor)
- Schedule a specific wake time
Here's my thoughts on the points below:
-
I tried this already. I have a smart plugin that I can control using a separate app on my mobile. It works on my macbook air, that if I turn on the smart plug, it will also turn on my macbook air since its plugged in on that smart plug. However, on my mac mini, this doesn't work. I already tried "Start up automatically after a power failure" but this will only work if the machine was turned off unexpectedly (like when there's power outage). That's the time start automatically after power failure would work.
-
Not sure how I would use this, since the power button for mac mini is under the device. It will be complicated to setup just to turn on the device.
-
Yes, I'm using a remote app on my laptop to connect to mac-mini. "Wake Up On LAN" is not supported on my mac mini.
Got it. Just to clarify, I said "sleep" because to test it, I clicked the Apple Icon on the top left then click sleep so the device goes to sleep. Then I tried to run the Wake Screen macro using remote trigger and it works. That's why I got curious on how that works and started a question regarding if KM is running while the mac is in "sleep"
EDIT: I'm just really curious how everything works because this app is so helpful and can do many things for me. Really helped me in a lot of situations.
I was worried about that, but you could always shut your Mac by terminating its power using the smart power switch. Yes, that's not very safe, so I don't recommend it, but it would probably work.
There are several ways to fix that. Firstly, just turn your Mac Mini sideways. Second, purchase the "Zeera MacForge Gen2 Aluminum Case". Either way, the problem is solved.
That's too bad. Clearly, you've done some homework.
I'm out of ideas, if you don't like any of my three ideas in this post.
No. Thanks for the ideas! They're great. I'm always open to new ideas and curious about what’s possible.
Then it almost certainly wasn't actually asleep -- especially if you issued the sleep command and then, almost immediately, Remote Triggered the macro.
Are you sure? Check the "Wake for network access" setting in System Settings -> Energy. It isn't exactly WoL, but may be enough for remote access without you having to run a macro too. I use Apple Remote Desktop to connect to sleeping Macs every day -- though you may need to change some network settings if the client machine isn't on the same subnet as the Mini.
Don't! Instead, put the SwitchBot or similar on a connected keyboard and have it tap the space bar
But by far the easiest way to have a computer available for remote access whenever you need it is to not let it sleep in the first place...