I use my own MacBook at work. When I show up there I open my MacBook's lid, enter my password and I'm ready to go. As soon as I enter my password, I want a few things to happen: launch a few applications, files and scripts to set up my working environment
Until now I was using the wireless network trigger. KM opened the applications, but too early it seems. Things like Slack and Gmail need manual reloads because they complain about a missing network connection.
My understanding is that the connection to the wireless network is established but the connection to the actual WWW takes a little bit longer. I don't know why but that's the only reasonable explanation I can come up with.
So my idea was to use the login trigger. I thought by entering my password I'm logging in. Turns out logging in from sleep or lock is not what's meant by this trigger, I guess. At least it does not fire when I lock my Mac and enter my password to log in again.
So what would be the correct trigger to set up my working environment?
My guess would be that it is connecting to wifi before you enter your login details. Thus the macro runs, but the screen is still locked, so most UI actions are blocked. Depending on your macro, that may cause your macro to fail.
With maybe a further short pause after that. I would set the action to timeout after 60 seconds and not notify, since it is quite possible your Mac will wake from sleep and connect to wifi and yet never actually unlock the screen (eg if the Mac wakes while sleeping to perform some silent task, or if you open the lid and then close it again).
Probably also a good idea to use a Semaphore Lock action with a very short timeout and no notification to ensure there is only ever one of these macros trying to run.
You could pause until you can connect to an external website, such as http://ipinfo.io/ip
This will loop until a valid connection can be made.
#!/bin/zsh -f
while { ! curl --connect-timeout 5 --max-time 5 -sfL 'http://ipinfo.io/ip' }
do
sleep 5
done
If you used that as a shell script in Keyboard Maestro that runs before the rest of your actions, you would know you are online when the rest of the actions trigger.
As a bonus, you could save the output of the script as variable (when the script does finally connect, it will output your external IP) and do certain things based on your external IP, if that was something you were interested in.
To make this more clear, I create an example here:
Thanks for your suggestions. Right now I'm sticking with the SCREENSAVER() == 0 method and a 3 second delay. That has been working for the last few days. As soon as it stops working I will gladly try one of the outline alternatives.