MacBooks and Auto WiFi Depending on Ethernet Availability Using Keyboard Maestro

When I connect an Ethernet cable to my MacBook, WiFi is automatically disabled. When I disconnect the Ethernet cable, WiFi is enabled again. This not standard behaviour. It seems like magic. so how did I do it?

Brett Terpstra recently posted a tip on how to turn a Mac’s WiFi on and off from the shell[1]. I remembered that Keyboard Maestro recently added functionality to allow the triggering of a script when a volume was mounted or unmounted[2].

Well, what does a volume mount have to do with an ethernet cable connection? I only “dock”[3] my MacBook to a USB extender, power and Ethernet. Whenever I plug in the USB extender, my media and backup drives become available. Sometimes I might disconnect my backup drive, but whenever I’m “docked”, my media drive entitled amazingly enough, “Media” is always connected.

So I set up a Volume mounted trigger on “Media” and this executed the following shell script, taken straight from Terpstra’s article:

networksetup -setairportpower en0 off

And I set up a corresponding shell script trigger for when “Media” is unmounted as follows:

networksetup -setairportpower en0 on

Voilà! I no longer have to manually turn WiFi off to take advantage of lightning fast Ethernet speeds when I’m plugged into my BT Infinity 2 router over the Gigabit Ethernet, and I no longer have to remember to enable WiFi when I unplug.

  1. “Quick Tip: Automating your Mac’s wifi power”  ↩
  2. “Major Changes for 6.0”  ↩
  3. I ordered a Zendock a lifetime ago on Kickstarter. They seem like nice people, but it’s been a very long time.  ↩

One thought on “MacBooks and Auto WiFi Depending on Ethernet Availability Using Keyboard Maestro”

Leave a Reply

Your email address will not be published. Required fields are marked *