Browse Source

Fixed inconsistency between `networksetup` and `scutil` in the naming of the Airport/Wi-Fi device

tags/v1.0.0
Robert Klep 13 years ago
parent
commit
135f8b7a90
2 changed files with 10 additions and 8 deletions
  1. +4
    -1
      README.md
  2. +6
    -7
      ToggleProxy.py

+ 4
- 1
README.md View File

@@ -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 Toggle the on/off state by clicking the icon, quit the application by
`Ctrl`-clicking the icon. `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 ## Prerequisites


* PyObjC: this should be already installed on your Mac, possible after * 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 ./dist/ToggleProxy.app/Contents/MacOS/ToggleProxy


This should output any errors to stdout, so you might get a clue as to why 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 ## Author & License




+ 6
- 7
ToggleProxy.py View File

@@ -35,9 +35,10 @@ class ToggleProxy(NSObject):


def loadNetworkServices(self): def loadNetworkServices(self):
""" load list of network services """ """ 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): def watchForProxyChanges(self):
""" install a watcher for proxy changes """ """ install a watcher for proxy changes """
@@ -76,10 +77,8 @@ class ToggleProxy(NSObject):


def toggleProxy_(self, sender): def toggleProxy_(self, sender):
""" callback for clicks on menu item """ """ callback for clicks on menu item """
event = NSApp.currentEvent()

# Ctrl pressed? if so, quit # Ctrl pressed? if so, quit
if event.modifierFlags() & NSControlKeyMask:
if NSApp.currentEvent().modifierFlags() & NSControlKeyMask:
NSApp.terminate_(self) NSApp.terminate_(self)
return return


@@ -88,7 +87,7 @@ class ToggleProxy(NSObject):
NSLog("interface '%s' not found in services?" % self.interface) NSLog("interface '%s' not found in services?" % self.interface)
return return
newstate = self.active and "off" or "on" newstate = self.active and "off" or "on"
commands.getoutput("networksetup setwebproxystate %s %s" % (
commands.getoutput("/usr/sbin/networksetup setwebproxystate %s %s" % (
servicename, servicename,
newstate newstate
)) ))


Loading…
Cancel
Save