hammerspoon2-docs
    Preparing search index...

    Namespace bluetooth

    Inspect, connect to and scan for Bluetooth devices, and watch them connect and disconnect. keyboard or a mouse paired with this Mac. These have battery levels and system-wide connect/disconnect events. Hammerspoon can connect to itself to read and write its GATT characteristics. macOS gives these a UUID identifier instead of revealing their address.

    hs.bluetooth.pairedDevices().forEach(d => console.log(d.name + " " + d.address))

    hs.bluetooth.connectedDevices()
    .filter(d => d.batteryLevel !== null)
    .forEach(d => console.log(d.name + ": " + d.batteryLevel + "%"))

    hs.bluetooth.on('connected', d => console.log(d.name + " connected"))
    hs.bluetooth.on('powerChanged', on => console.log("Bluetooth is " + (on ? "on" : "off")))

    const nearby = await hs.bluetooth.scan({ seconds: 5 })
    nearby.forEach(p => console.log((p.name ?? p.identifier) + " " + p.rssi + " dBm"))

    macOS asks the user for Bluetooth permission the first time this module talks to Bluetooth. Use hs.permissions.checkBluetooth() to see whether it has been granted.

    Variables

    isInquiring
    isScanning
    powered

    Functions

    connectedDevices
    connectedPeripherals
    device
    inquiry
    off
    on
    once
    pairedDevices
    peripheral
    scan
    stopInquiry
    stopScan