Created
March 28, 2012 08:51
-
-
Save rnaveiras/2224859 to your computer and use it in GitHub Desktop.
toggle bluetooth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import objc | |
bundle = objc.loadBundle("IOBluetooth", globals(),bundle_path=objc.pathForFramework(u'/System/Library/Frameworks/IOBluetooth.framework')) | |
if not bundle: | |
raise RuntimeError, "initFrameworkWrapper" | |
# request handles to functions | |
fs = [('IOBluetoothPreferenceGetControllerPowerState', 'oI'),('IOBluetoothPreferenceSetControllerPowerState','vI')] | |
ds = {} | |
objc.loadBundleFunctions(bundle,ds,fs) | |
# did we get everything we need? | |
for (name, handle) in fs: | |
if not name in ds: | |
raise RuntimeError, "failed to load: " + name | |
if ds['IOBluetoothPreferenceGetControllerPowerState']() == 1: | |
ds['IOBluetoothPreferenceSetControllerPowerState'](0) | |
else: | |
ds['IOBluetoothPreferenceSetControllerPowerState'](1) | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment