Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Unhyper

macrumors regular
Original poster
Apr 7, 2010
168
14
Finland
I would like to find a convenient way to turn Ethernet on only when I need web access. I'd prefer not to set up a WiFi for this.

I'd like to find a way to either have a menu icon upon pressing on which I could select On or Off for Ethernet. Other than that, a Control Center switch would be nice. As a last resort, a Shortcut for switching between the two states or even a different one for ON and OFF. I assume those could be managed with a shell script of some kind.

I tried to google to see if there already exists an app for this but I didn't find any.

Alternatively I'd settle for a way to block all connections when VPN is off, and simply use the VPN as a switch for this, but my impression is that some applications (system ones in particular) can simply bypass it.
 
There are multiple ways, here’s a simple AppleScript that can be saved as an app:

AppleScript:
set question to display dialog "Turn Ethernet:" buttons {"Off", "On", "Cancel"} default button 1
set answer to button returned of question
if answer is equal to "Off" then
    do shell script "networksetup -setnetworkserviceenabled Ethernet off"
end if
if answer is equal to "On" then
    do shell script "networksetup -setnetworkserviceenabled Ethernet on"
end if
return
 
Alternatively I'd settle for a way to block all connections when VPN is off, and simply use the VPN as a switch for this, but my impression is that some applications (system ones in particular) can simply bypass it.
Some VPN service clients include a "kill switch" feature. The "kill switch" will disable networking if the VPN is not active.
 
  • Like
Reactions: Unhyper
Some VPN service clients include a "kill switch" feature. The "kill switch" will disable networking if the VPN is not active.
That is a good tip. Unfortunately my VPN's kill switch does not disable connections on macOS if the VPN connection is closed by the user. It supposedly works on Windows or Linux. Still, a useful feature.

There are multiple ways, here’s a simple AppleScript that can be saved as an app:

AppleScript:
set question to display dialog "Turn Ethernet:" buttons {"Off", "On", "Cancel"} default button 1
set answer to button returned of question
if answer is equal to "Off" then
    do shell script "networksetup -setnetworkserviceenabled Ethernet off"
end if
if answer is equal to "On" then
    do shell script "networksetup -setnetworkserviceenabled Ethernet on"
end if
return
I saved this as an app and made a menu shortcut for it. Works perfectly! Thank you for taking the time to write it.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.