ReadonlyavailableAll sample rates (in Hz) that this device supports. For devices that support a range, both the minimum and maximum are included.
Output stereo balance in the range 0.0 (full left)–1.0 (full right),
or null if balance control is not available. Setting a value outside 0.0–1.0
logs an error and leaves the balance unchanged.
ReadonlyidThe CoreAudio object ID of this device.
ReadonlyinputNumber of input channels, or 0 if the device has no input.
Whether input is muted. Always false if the device has no mutable input.
Input (microphone) volume scalar in the range 0.0–1.0, or null if
the device has no controllable input volume. Setting a value outside 0.0–1.0 logs
an error and leaves the volume unchanged (Hammerspoon v1 used 0–100).
ReadonlyisWhether this device has input streams (can record audio).
ReadonlyisWhether any process (not just Hammerspoon) is currently using this device for input
or output - e.g. a call or dictation app has opened the microphone, or music is playing.
Listen for the "inUse" event to be told when this changes.
ReadonlyisWhether this device has output streams (can play audio).
ReadonlyjackWhether a jack (e.g. headphones) is connected to this device. Always false if the device
does not support jack sensing. Output jack state is reported for devices with output,
otherwise input jack state. Listen for the "jack" event to be told when this changes.
Whether output is muted. Always false if the device has no mutable output.
ReadonlynameThe human-readable name of this device (e.g. "Built-in Output").
ReadonlyoutputNumber of output channels, or 0 if the device has no output.
The current nominal sample rate in Hz (e.g. 44100), or null if unknown.
ReadonlytransportThe transport mechanism: "built-in", "usb", "bluetooth", "bluetooth-le",
"hdmi", "display-port", "firewire", "airplay", "avb",
"thunderbolt", "virtual", "aggregate", "pci", or "unknown".
ReadonlyuidThe persistent unique identifier for this device.
Output volume scalar in the range 0.0–1.0, or null if the device has
no controllable output volume. Setting null is a no-op, and setting a value outside
0.0–1.0 logs an error and leaves the volume unchanged (Hammerspoon v1 used 0–100).
The current input data source as { id, name }, or null if unavailable.
A dictionary containing the id and name of the current input data source
The current output data source as { id, name }, or null if unavailable.
A dictionary containing the id and name of the current output data source
All available input data sources as an array of { id, name } objects.
A dictionary containing the ids and names of all available input data sources
Remove a previously registered per-device event listener.
The event the listener was registered for
The function originally passed to on
Register a listener for a named per-device property-change event.
Available events:
"vmout" — output volume changed. The listener receives the new volume."vmin" — input volume changed. The listener receives the new inputVolume."mout" — output mute state changed. The listener receives the new muted value."min" — input mute state changed. The listener receives the new inputMuted value."rate" — sample rate changed. The listener receives the new sampleRate."dsout" — output data source changed. The listener receives the new
currentOutputDataSource()."dsin" — input data source changed. The listener receives the new
currentInputDataSource()."balance" — output stereo balance changed. The listener receives the new balance."inUse" — the device started or stopped being used by any process. The listener
receives the new isInUse value."jack" — a jack (e.g. headphones) was connected or disconnected. The listener
receives the new jackConnected value."config" — the device's configuration changed (e.g. its streams or channel layout);
any properties you have cached for it may be stale. The listener receives nothing.The value is read when the listener is called, and is null if the device can't
report it. "inUse" and "jack" always pass a boolean, false if the device can't
report it, as isInUse and jackConnected do.
The event to listen for
Called when the event occurs, with the new value of the property that changed (see above); for "config" it is passed nothing
Register a listener that fires at most once for a per-device event.
The event to listen for
Called once, then automatically removed. Passed the new value, as for on()
All available output data sources as an array of { id, name } objects.
A dictionary containing the ids and names of all available output data sources
Select an input data source by its numeric ID.
The id value from inputDataSources()
true on success
Select an output data source by its numeric ID.
The id value from outputDataSources()
true on success
Make this device the system alert sound (effect) device.
true on success
Make this device the system default input device.
true on success
Make this device the system default output device.
true on success
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 id, name, uid, isInput, isOutput, transportType, isInUse, jackConnected, inputChannels, outputChannels, volume, muted, balance, inputVolume, inputMuted and sampleRate. Values the device doesn't support are null
An audio device attached to the system.
Obtain instances via
hs.audiodevicemodule methods — do not instantiate directly.Getting and setting volume
Watching for changes