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 <mkoistinen@gmail.com>
tags/v1.0.0
Martin Koistinen 11 years ago
parent
commit
2ced7bdbd7
1 changed files with 12 additions and 5 deletions
  1. +12
    -5
      ToggleProxy.py

+ 12
- 5
ToggleProxy.py View File

@@ -63,12 +63,19 @@ class ToggleProxy(NSObject):
return SCDynamicStoreCopyValue(self.store, '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 """
self.services = {}
for interface in SCNetworkInterfaceCopyAll():
device = SCNetworkInterfaceGetBSDName(interface)
servicename = SCNetworkInterfaceGetLocalizedDisplayName(interface)
self.services[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)
self.services[bsdname] = name

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


Loading…
Cancel
Save