如何使用 NSBundle Mac 连接到可用的蓝牙设备?

问题描述

我正在尝试编写代码,以便在我的 2 台 Mac 之间自动切换我的魔术鼠标和键盘的蓝牙连接。为此,我必须与它们断开连接,然后在其他设备上重新连接。我已经找到了一种使用以下方法断开所有设备的方法

from Foundation import NSBundle

IOBluetooth       = NSBundle.bundleWithIdentifier_('com.apple.Bluetooth')
IOBluetoothDevice = IOBluetooth.classNamed_('IOBluetoothDevice')

# remove paired devices
try:
    devices = list(IOBluetoothDevice.pairedDevices())
except:
    devices = []
for device in devices:
    try:
        device.remove()
    except:
        pass

这完美地删除了它们,但我似乎无法找到连接到可用设备的方法。 我尝试使用 IOBluetoothDeviceInquiry 类尝试连接,但这也不起作用:

IOBluetoothDevice2 = IOBluetooth.classNamed_('IOBluetoothDeviceInquiry')

devices = list(IOBluetoothDevice2.foundDevices())

返回

  File "/Users/yassine/Documents/Coding/Python/Experiments/Auto_switch/Auto_switch.py",line 7,in <module>
    devices = list(IOBluetoothDevice2.foundDevices())
TypeError: Missing argument: self

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)