How Do I Detect If I am Connected to a Wired, Ethernet Network?

I need a macro that will connect via Wi-Fi IF my Mac is NOT connected via a Ethernet cable, and IF I am connected via Ethernet, then disable Wi-Fi.

But I do not see a way to determine IF my Mac is connected via Ethernet.
Note that even when I am connected via Ethernet, the WiFi connection is also available.

Any ideas?

Hey JM,

Here’s a place to start:

-Chris

Thanks for the suggestion, Chris.
Unfortunately I'm so ignorant of shell scripts that I can't really make use of anything from that reference.

Surely there must be a routine somewhere that can return true/false to isEthernetConnected()

I'll keep looking. . .

Hey JM,

Run this from an Execute a Shell Script action:

ifconfig -a

Then search for a line that looks like this:

media: autoselect (100baseTX ) status: active

If you find it then your Ethernet is active.

You can use something like this to toggle Wi-Fi on/off.

-Chris

1 Like

Thanks, Chris.

From your two scripts, I have cobbled together this simple test macro.
It seems to work, but I still hope to find direct AppleScript solution to detecting the Ethernet connection.

##Macro Library   Turn off wi-fi when on ethernet


####DOWNLOAD:
<a class="attachment" href="/uploads/default/original/2X/7/7ce00f9e53656ea076555a8249d5ecf9dd912683.kmmacros">Turn off wi-fi when on ethernet.kmmacros</a> (6.8 KB)

---

###ReleaseNotes

TBD

---

<img src="/uploads/default/original/2X/3/3b3b717ce38065bcf64edfe003420ff70dadb940.png" width="511" height="849">

Here's the RegEx I used:
`(?im)media: autoselect \(1000?baseT.+\n.+status: active$`