Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use PyObjC to turn off and on the wireless interfaces of a Mac?

How do you use PyObjC to turn off and on the wireless interfaces of a Mac? My research to date has lead me to the Cocoa Framework and PyObjC. On the Mac Developer website I found an example of a wireless interface management application demonstrating how to use the Cocoa Framework to toggle on and off the wireless interfaces of a Mac here. This example indicates that the CWInterface under the CoreWLAN Framework is necessary to accomplish the task of turning off and on the wireless interface of a Mac. However, PyObjC doesn't seem to include the CoreWLAN Framework from Cocoa in its wrapper here . Any thoughts on how to accomplish this task? Could I implement my own PyObjc objects to call the CoreWLAN Framework, and if so what would be a good resource on how to do this? Thanks for your time! Anything helps.

like image 871
user1626814 Avatar asked Aug 27 '12 05:08

user1626814


1 Answers

You can load the framework manually using:

import objc
objc.loadBundle('CoreWLAN', 
       bundle_path='/System/Library/Frameworks/CoreWLAN.framework', 
       module_globals=globals())

The classes in the framework are now available in the module globals dictionary.

Get the wireless interface with:

iface = CWInterface.interface()

You can then turn the power on or of with:

iface.setPower_error_(True, None)

or

iface.setPower_error_(False, None)

P.S. I'll add this framework in a future release, one reason it is not available at the moment is that I didn't know this is a public framework.

like image 145
Ronald Oussoren Avatar answered Oct 12 '22 07:10

Ronald Oussoren