Shell Script to Pause Until You Are Online

If you have actions that need to wait until you are connected to the Internet, not just the Wi-Fi network, you can use this:


[MODERATOR's NOTE: This is an Action, not a Macro. If you double-click on it after downloading, it will be inserted into your current Macro that is open for editing, without any notice.]


Execute a Shell Script.kmactions (818 B)

as the first step, and it will wait until you are connected before any of the rest of the steps are taken.

I set the timeout to 1 minute. Adjust to your wishes.

1 Like

Thanks for sharing.

I need a bit of clarification.

  1. Does it require wifi? I have a ethernet connection.
  2. What are the units of the numbers? Minutes?
  3. Where is the timeout set?
    • You said you set it to 1 minute, but it looks like 5 to me.
  4. What is the reliability of the site ipinfo.io ?
    • How did you pick it?
    • Other good choices?

Hi JMichaelTX

Good questions. I was in a bit of a rush when I posted this, so I didn't do a very good job of explaining it. Let me see if I can address your questions.

  1. It should not matter what kind of connection you have, Ethernet, Wi-Fi, or other. All this does is check that you can connect to an external website somehow.

  2. The “sleep 5” means “wait 5 seconds”. Since this is a “while” loop, it will run again once the “sleep” expired. Similarly, the '5's in the curl command also mean seconds.

  3. The timeout I set was for the Keyboard Maestro macro itself, by using the “Set Action Timeout” option in Keyboard Maestro’s Editor.

  4. a) I have used ipinfo.io to check my external IP for years. I picked it because it’s actually even faster than I page I made for the same purpose.

  5. b) There are lots of good choices, I suppose. Trying to connect to google.com or apple.com would work too, but I chose ipinfo.io because it actually gives some useful information (your external IP) when you do connect.

I hope that helps!

Tj

3 Likes