Wi-Fi off while the dock has a network
A small script and a LaunchAgent turn Wi-Fi off while the CalDigit TS5 has a working network, and back on when it doesn't.
I’ve got a CalDigit TS5 on my desk with a network cable in it, and I wanted Wi-Fi to turn off while I’m on the cable and back on when I’m not.
Checking for the dock isn’t enough, a dock with no cable or a cable to a dead switch shouldn’t leave me with no network.
So Wi-Fi goes off only when the dock’s Ethernet has a link and an IPv4 address.
The device name can change, so we’ll find it by the dock’s MAC address, which you can get from networksetup -listallhardwareports, and add the following to ~/.local/bin/dock-wifi-toggle.
#!/bin/zshDOCK_MAC="aa:bb:cc:dd:ee:ff"
wifi=$(networksetup -listallhardwareports | awk '/Hardware Port: Wi-Fi/{getline; print $2}')dock=$(networksetup -listallhardwareports | grep -i -B1 "$DOCK_MAC" | awk '/Device:/{print $2}')
if [[ -n "$dock" ]] && ifconfig "$dock" 2>/dev/null | grep -q "status: active" \ && ipconfig getifaddr "$dock" >/dev/null 2>&1; then want=offelse want=onfi
current=$(networksetup -getairportpower "$wifi" | awk '{print tolower($NF)}')if [[ "$current" != "$want" ]]; then networksetup -setairportpower "$wifi" "$want" logger "dock-wifi-toggle: Wi-Fi $want (dock=${dock:-none})"fiChanging the Wi-Fi power is a network change too, so the script starts again right after it runs, and the check before we switch means that second run does nothing.
We don’t need a timer to run it, /Library/Preferences/SystemConfiguration changes on any network change, so we can point a LaunchAgent at it with the following in its plist.
<key>WatchPaths</key><array> <string>/Library/Preferences/SystemConfiguration</string></array><key>RunAtLoad</key><true/><key>ThrottleInterval</key><integer>5</integer>Pull the cable out and Wi-Fi comes on, plug it back in and it goes off once DHCP is done.
You can watch that with the following command, with the full path because log is a builtin in zsh.
/usr/bin/log stream --predicate 'eventMessage CONTAINS "dock-wifi-toggle"'It also fires when the laptop wakes
After a few weeks I took a look at the log and there were 52 changes in 14 days, 24 of them from a single day, in pairs 5 to 10 seconds apart.
2026-11-04 13:32:20.700 dock-wifi-toggle: Wi-Fi on (dock=en11)2026-11-04 13:32:31.006 dock-wifi-toggle: Wi-Fi off (dock=en11)Every pair I checked starts 5 or 6 seconds after a wake in pmset -g log, including the dark wakes where the screen stays off.
The link on the dock’s Ethernet bounces when the laptop wakes and the address goes with it, so for a few seconds the cable has no network.
The script does what I told it to do, Wi-Fi on, and off again once DHCP is bound.