Browse Source

We need the service name, not the LocalizedDisplayName

/usr/sbin/networksetup requires the unique, user-defined service name, E.g., "Built-in Ethernet" or, in my case "Ethernet (Intel)" which is what I named mine to distinguish it from any other Ethernet interfaces (I have multiple).

Unfortunately, SCNetworkInterfaceGetLocalizedDisplayName is rather poorly documented, but I think it was intended to provide a localized version of "Ethernet" or "Bluetooth".  In practice, I don't know if other languages define a different word for these.  This would return the same string "Ethernet" (on EN-localized systems) on systems with multiple Ethernet interfaces, so isn't helpful.

Signed-off-by: Martin Koistinen <>
Martin Koistinen 10 years ago
1 changed files with 12 additions and 5 deletions
  1. +12

+ 12
- 5 View File

@@ -63,12 +63,19 @@ class ToggleProxy(NSObject):
return SCDynamicStoreCopyValue(, 'State:/Network/Global/IPv4')['PrimaryInterface']

def loadNetworkServices(self):
""" load list of network services """
""" Load and store a list of network services indexed by their BSDName """ = {}
for interface in SCNetworkInterfaceCopyAll():
device = SCNetworkInterfaceGetBSDName(interface)
servicename = SCNetworkInterfaceGetLocalizedDisplayName(interface)[device] = servicename
# Create a dummy preference reference
prefs = SCPreferencesCreate(kCFAllocatorDefault, 'PRG', None)
# Fetch the list of services
for service in SCNetworkServiceCopyAll(prefs):
# This is what we're after, the user-defined service name e.g., "Built-in Ethernet"
name = SCNetworkServiceGetName(service)
# Interface reference
interface = SCNetworkServiceGetInterface(service)
# The BSDName of the interface, E.g., "en1", this will be the index of our list
bsdname = SCNetworkInterfaceGetBSDName(interface)[bsdname] = name

def watchForProxyChanges(self):
""" install a watcher for proxy changes """