14

When I wake my machine in the morning, it often stays blank because there's some conflict between my 4k monitor and the 'Your computer name has changed for the 3950th time' dialogue that means both screens are off until I dismiss the dialogue I can't see.

I don't want to have to turn wifi on and off manually - we have computers to do things automatically for us - and I need a wired connection while I'm at my desk.

So can I tell the Mac only to enable to wifi if eth0 is inactive?

Or turn the 'Your computer name has changed' dialogue into a notification that doesn't need manual dismissal, because I really don't care what number Apple has decided to add to it today?

3
  • 8
    Simply change the service priority of the interfaces by moving the Ethernet interface to the top in System Prefs > Network > Gear at the bottom > Set service order...
    – klanomath
    Mar 30, 2017 at 8:00
  • @klanomath Good suggestion. But work said it was time to refresh my laptop and I opted to switch to Linux instead. Much easier than fighting Apple every step of the way. Mar 26, 2019 at 9:46
  • See as well apple.stackexchange.com/questions/98815/…
    – Wollmich
    Feb 15, 2021 at 9:18

3 Answers 3

10

You have several solutions:

  1. https://gist.github.com/albertbori/1798d88a93175b9da00b

This is a bash script that will automatically turn your wifi off if you connect your computer to an ethernet connection and turn wifi back on when you unplug your ethernet cable/adapter. If you decide to turn wifi on for whatever reason, it will remember that choice. This was improvised from this mac hint to work with Yosemite, and without hard-coding the adapter names. It's supposed to support growl, but I didn't check that part. I did, however, add OSX notification center support. Feel free to fork and fix any issues you encounter.

  1. https://macperformanceguide.com/blog/2014/20141118_0958-OSX_Yosemite-disable-WIFI.html

  2. The associated google search :

https://www.google.fr/search?client=safari&rls=en&q=disable+wifi+if+ethernet+osx&ie=UTF-8&oe=UTF-8&gfe_rd=cr&ei=VL_cWMj1B-zUXt3CkLAM

2
  • 4
    Right now this stackoverflow post is the top Google result for "mac disable wifi on ethernet". This makes your solution #3 moot...
    – Chris
    May 22, 2020 at 2:22
  • 1
    LOL Any google search-based solution is self-evidently moot, especially when it's google.fr (or any other localized search for that matter).
    – Brunox13
    Sep 2, 2020 at 15:43
4

I realise this question is a bit old... however, as there are multiple ways of accomplishing the same result, I thought it worth sharing one more: using Hammerspoon and a couple of snippets of Lua code.

Hammerspoon is a tool to automate various operations on a Mac. I'm not associated to it in any way, I literally installed it to try and achieve the same purpose as the OP.

For anything you want to automate, you write little Lua scripts; in this case, I created a network.lua file which I saved next to the main configuration file, $HOME/.hammerspoon/init.lua. Here's the contents of both:

# init.lua
-- Imports
local homeNetwork = require "network"

-- Toggle WiFi based on Ethernet being connected or not
homeNetwork.setEthernetInterface("USB 10/100/1000 LAN")
systemWatcher = hs.caffeinate.watcher.new(homeNetwork.handleWifi)
systemWatcher:start()

# network.lua
local M = {}
local ethernetInterface

local function isEthernetConnected()
    ipv4 = hs.network.primaryInterfaces()
    activeInterfaceName = hs.network.interfaceName(ipv4)

    return activeInterfaceName == ethernetInterface
end

local function toggleWifi()
    desiredState = not isEthernetConnected() and true or false

    if hs.wifi.interfaceDetails()['power'] ~= desiredState then
        hs.wifi.setPower(desiredState)

        newState = desiredState and "on" or "off"
        hs.alert.show("Turning wifi " .. newState)
    else
        hs.alert.show("Wifi already in the desired state")
    end
end

function M.setEthernetInterface(ethernetInterfaceName)
    ethernetInterface = ethernetInterfaceName
end

function M.handleWifi(event)
    if event == hs.caffeinate.watcher.systemDidWake then
        toggleWifi()
    elseif event == hs.caffeinate.watcher.screensDidUnlock then
        toggleWifi()
    end
end

return M

The only thing you'll have to customise is the name of your Ethernet interface in init.lua; in my case it's "USB 10/100/1000 LAN" because I'm using a dock. You can find the name for yours in the Network section of your System Preferences.

2

It hasn't been updated in a while, but ControlPlane handles this very well.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .