From 135f8b7a903635dc2b7568794994cd0fe750ae83 Mon Sep 17 00:00:00 2001 From: Robert Klep Date: Wed, 16 Nov 2011 18:15:27 +0100 Subject: [PATCH] Fixed inconsistency between `networksetup` and `scutil` in the naming of the Airport/Wi-Fi device --- README.md | 5 ++++- ToggleProxy.py | 13 ++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 24b4437..6a2a8e4 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,9 @@ only an up-arrow when the proxy is not active. Toggle the on/off state by clicking the icon, quit the application by `Ctrl`-clicking the icon. +*NB*: this is not a proxy manager, you have to configure proxies from Mac +OS X Network preferences first before this app makes any sense. + ## Prerequisites * PyObjC: this should be already installed on your Mac, possible after @@ -40,7 +43,7 @@ this from the same directory as `setup.py`: ./dist/ToggleProxy.app/Contents/MacOS/ToggleProxy This should output any errors to stdout, so you might get a clue as to why -it's not working. If it warrants an issue-report, you're welcome! +it's not working. If it warrants an issue report, you're welcome! ## Author & License diff --git a/ToggleProxy.py b/ToggleProxy.py index c81aee3..5070552 100644 --- a/ToggleProxy.py +++ b/ToggleProxy.py @@ -35,9 +35,10 @@ class ToggleProxy(NSObject): def loadNetworkServices(self): """ load list of network services """ - self.services = {} - for key, dictionary in SCDynamicStoreCopyMultiple(self.store, None, [ 'Setup:/Network/Service/.*/Interface' ]).items(): - self.services[dictionary['DeviceName']] = dictionary['UserDefinedName'] + self.services = {} + output = commands.getoutput("/usr/sbin/networksetup listnetworkserviceorder") + for service, device in re.findall(r'Hardware Port:\s*(.*?), Device:\s*(.*?)\)', output): + self.services[device] = service def watchForProxyChanges(self): """ install a watcher for proxy changes """ @@ -76,10 +77,8 @@ class ToggleProxy(NSObject): def toggleProxy_(self, sender): """ callback for clicks on menu item """ - event = NSApp.currentEvent() - # Ctrl pressed? if so, quit - if event.modifierFlags() & NSControlKeyMask: + if NSApp.currentEvent().modifierFlags() & NSControlKeyMask: NSApp.terminate_(self) return @@ -88,7 +87,7 @@ class ToggleProxy(NSObject): NSLog("interface '%s' not found in services?" % self.interface) return newstate = self.active and "off" or "on" - commands.getoutput("networksetup setwebproxystate %s %s" % ( + commands.getoutput("/usr/sbin/networksetup setwebproxystate %s %s" % ( servicename, newstate ))