PyObjC: IOBluetoothUI Framework

12.1 · active · verified Tue Apr 14

pyobjc-framework-iobluetoothui provides Python wrappers for Apple's IOBluetoothUI.framework on macOS, allowing Python applications to interact with Bluetooth-related user interface components. It is part of the larger PyObjC project, which bridges Python and the Objective-C runtime. The current version is 12.1, with releases typically tied to new macOS SDKs and Python version support cycles.

Warnings

Install

Imports

Quickstart

This quickstart initializes a macOS Cocoa application, sets up a simple delegate, and then displays the IOBluetoothServiceBrowserController as a modal dialog. The application will wait for the user to dismiss the Bluetooth browser before terminating. This demonstrates how to interact with a core UI component from the IOBluetoothUI framework.

from Foundation import NSObject
from AppKit import NSApplication
from PyObjCTools import AppHelper
from IOBluetoothUI import IOBluetoothServiceBrowserController

class AppDelegate(NSObject):
    def applicationDidFinishLaunching_(self, notification):
        print("Application finished launching. Showing Bluetooth Service Browser...")
        self.browserController = IOBluetoothServiceBrowserController.withServiceBrowserController_()
        if self.browserController:
            # Options can be specified here, e.g., 0 for default
            self.browserController.setOptions_(0) 
            # showModal_ blocks until the browser dialog is dismissed
            self.browserController.showModal_(None) 
            print("Bluetooth Service Browser dismissed.")
        else:
            print("Failed to create IOBluetoothServiceBrowserController.")
        # In a real app, you might want to quit the app or keep it running
        # For this quickstart, we'll quit after the modal dialog is dismissed.
        NSApplication.sharedApplication().terminate_(None)

def main():
    app = NSApplication.sharedApplication()
    delegate = AppDelegate.alloc().init()
    app.setDelegate_(delegate)
    # Run the Cocoa event loop
    AppHelper.runEventLoop()

if __name__ == "__main__":
    main()

view raw JSON →