ReadonlyaddressThe device's Bluetooth address, in the form xx-xx-xx-xx-xx-xx.
ReadonlybatteryThe device's battery level as a percentage, or null if macOS doesn't know it.
This is what macOS itself reports: for Apple's Magic accessories from the system, and for AirPods and Beats from what macOS last heard from them. For earbuds it is the lower of the two buds; see batteryLevels for each one. For a device that reports its battery over BLE instead, read it with lowEnergyPeripheral() and readBatteryLevel().
ReadonlybatteryThe individual battery levels of a device with several batteries, such as earbuds and their case, or null if it has only one (or none is known).
The object has any of left, right and case, each a percentage.
ReadonlyclassThe device's raw Bluetooth Class of Device value.
ReadonlyisWhether macOS currently has the device connected.
ReadonlyisWhether the device is marked as a favorite in macOS.
ReadonlyisWhether the device is paired with this Mac.
ReadonlylastWhen the device was last used or found by an inquiry, in Unix seconds, or null if unknown.
ReadonlymajorThe major device class, e.g. 4 for audio devices or 5 for peripherals such as keyboards and mice.
ReadonlyminorThe minor device class, whose meaning depends on majorClass.
ReadonlynameThe device's name, or null if it hasn't reported one.
ReadonlyrssiThe signal strength in dBm that macOS last measured for the device, or null if there is none. Call readRSSI() for a fresh reading from a connected device.
ReadonlyserviceThe major service classes the device advertises, as a bitmask.
ReadonlyserviceThe names of the device's classic Bluetooth (SDP) services, e.g. ["Audio Sink", "AVRCP Controller"].
ReadonlytypeThe type name for JavaScript introspection. Always "HSBluetoothDevice".
Connects the device to the Mac, the same way macOS would, e.g. so headphones become available as an audio device.
A Promise resolving to this device once it's connected, or rejecting if the connection fails or takes longer than 20 seconds
Disconnects the device from the Mac. This ends macOS's own connection, not just Hammerspoon's, as if you had disconnected it in System Settings.
A Promise resolving to this device once it's disconnected
Finds the BLE peripheral of a connected device that also speaks Bluetooth Low Energy, such as a Magic Keyboard or a heart-rate strap, so you can use its GATT services.
macOS doesn't link a paired device to its BLE side, so this looks for the BLE peripheral connected to the Mac with the same name. It rejects rather than guess if several have that name, and resolves to null if none does (e.g. the device doesn't use BLE, or it was renamed after pairing). The peripheral still needs connect() before its GATT methods can be used.
A Promise resolving to the device's peripheral, or null if it has none. Rejects if the device isn't connected, several peripherals match, or Bluetooth is unavailable
Remove a previously registered listener for this device's events.
The event the listener was registered for
The function originally passed to on
Register a listener for this device's events.
Listeners for "connected" and "disconnected" are called with no arguments whenever macOS connects or disconnects the device. A device with listeners keeps working after you drop your reference to it.
The event to listen for
Called when the event occurs
Reads the current signal strength of a connected device.
A Promise resolving to the signal strength in dBm, or rejecting if the device isn't connected
Returns a plain object describing this device, for JSON serialisation
JSON.stringify() calls this automatically, so you rarely need to call it yourself.
An object with the device's name, address, isPaired, isConnected, rssi, batteryLevel, batteryLevels, majorClass and minorClass
A Bluetooth device macOS knows: one paired with this Mac, or one found by
hs.bluetooth.inquiry().Obtain devices from the
hs.bluetoothmodule; do not instantiate them directly. A device is identified by itsaddress, and the same device is returned as the same object for as long as you hold on to it.Bluetooth Low Energy (BLE) peripherals found by
hs.bluetooth.scan()areHSBluetoothPeripheralobjects instead. A paired device that also speaks BLE can give you its peripheral withlowEnergyPeripheral(), e.g. to read its GATT characteristics.Battery levels