Which trigger to use to set up working environment in the morning?

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?

Maybe use Pause after the wireless network trigger? If it takes 40 or 50 seconds for the web to become accessible, a pause could help:

1 Like

Good suggestion, thank you. I had the same idea and added a delay of 10 seconds. Will try that for now but hoped for a more elegant solution.

1 Like

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.

You could try:

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.

2 Likes

Will try that. Thank you, Peter.

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:

https://forum.keyboardmaestro.com/t/shell-script-to-pause-until-you-are-online/11261

2 Likes

For several years now I've use a macro with these triggers:

image
which fires with either trigger.

And then a pause of 15 sec.

YMMV.

This has worked for me with both my iMac-27 connected by cable to my router (always on) and my MBP connected by wifi.

It has always worked for me, but my router is connected to a cable modem, which is always on, always connected.

1 Like

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.

Again, thank you very much :ok_hand: