Skip to content

Instantly share code, notes, and snippets.

@rnaveiras
Created March 28, 2012 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rnaveiras/2224859 to your computer and use it in GitHub Desktop.
Save rnaveiras/2224859 to your computer and use it in GitHub Desktop.
toggle bluetooth
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