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