Trigger macro while Mac asleep and wifi off

A macro (periodic) triggers every 30 seconds actioning if statements, the if statements rely on changes to a website which in turn relies on wifi, the wifi turns off when the MacBook cover is closed or display is off. AppleScript is checking changes to Safari browser.

  1. Is it possible to stop the wifi from turning off when the cover is closed or the display is off?
  2. Is it possible for the the macros to continue to trigger and run (applescripts) while the cover is closed and or the display is off.

I haven't been able to find a solution to this issue on the forum.

Wifi shouldn't be disabled if the display is asleep but the Mac is awake. But if the cover is closed, your Mac is sleeping (assuming you're not using an external display), and Wifi is off. It can wake for incoming network activity, but it can't actively use wifi, nor can it run macros, etc.—because it's sleeping.

If you want the Mac to be doing things—on wifi or not—you need to keep it awake. Sleeping just the display should handle that. Go to System Settings > Battery > Options, and make sure "Prevent automatic sleeping on power adapter when the display is off" is enabled. You will have to keep the Mac plugged in, though. It will then stay awake at all times as long as it's plugged in.

-rob.

1 Like

"Prevent automatic sleeping on power adapter when the display is off" is already enabled, also power is connected.

Then there’s something about the macro that isn’t working properly. Are there any entries in the log files?

1 Like

Are these changes supposed to be visible? In other words your macro is doing something that involves the user interface - like clicking a weblink, for example?

If that's the case then if you can't see it (because the screen is off) neither can KM so your macro won't work. Otherwise something else is going on.

Why not share your macro here to save us having to guess what's going on?

3 Likes

Yes changes from internet are updated on the website, the macro looks for changes on the website then triggers when the If statement conditions are met.

Execute Shell Script
caffeinate -i -t 20 Execute asynchronously.
Notify on failure.
Execute Shell Script
caffeinate -m -t 20 Execute asynchronously.
Notify on failure.
tell application System Events
tell process Google Chrome
--17th element is the requested asset name
--get first loan requested asset name
get name of static text 3 of group 1 of group 1 of group 2 of group 1 of group 1 of group 1 of group 2 of group 1 of group 1 of group 2 of group 1 of group 1 of group 1 of UI element 3 of group 1 of group 1 of group 1 of group 1 of window 1
end tell
end tell
Save trimmed results without errors to variable “Loan1RequestedAssetType”.
Get loan 1 requested asset name
tell application System Events
tell process Google Chrome
--17th element is the requested asset name
--get first loan requested asset name
get name of static text 3 of group 1 of group 1 of group 2 of group 1 of group 1 of group 1 of group 2 of group 1 of group 1 of group 2 of group 1 of group 1 of UI element 3 of group 1 of group 1 of group 1 of group 1 of window 1
end tell
end tell Save trimmed results without errors to variable “Loan1ARequestedAssetType”.

Well, in the context of KM, to do anything that involves the user interface (including GUI scripting) requires that the screen actually be on. As I said - if it isn't visible to your eyes, then it won't be visible to KM I'm afraid.

Your options then are

  1. Leave your screen on
  2. Change your macro to use HTML POST/GET or perhaps curl - but I'm no expert in that.

Maybe there are other options that others can suggest?

How about I use this caffeinate -u -t 10
Then turn off the brightness of the display so that it is not showing but the system is live working in the background. I guess this will work? Display is manually turned off but system is awake and working as normal.

That's beyond my experience but you can try. It would be of interest to other users of KM - now and in the future - if you would report back here how you get on. Good luck :smiley: