hammerspoon2-docs
    Preparing search index...

    Class HSAudioDevice

    An audio device attached to the system. Obtain instances via hs.audiodevice module methods — do not instantiate directly.

    const dev = hs.audiodevice.defaultOutputDevice();
    if (dev) {
    console.log(dev.volume); // 0.0 – 1.0, or null
    dev.volume = 0.5;
    }
    const dev = hs.audiodevice.defaultOutputDevice();
    if (dev) {
    var fn = function(event) { console.log("Device event:", event); };
    dev.addWatcher(fn);
    // later…
    dev.removeWatcher(fn);
    }
    Index

    Constructors

    Properties

    availableSampleRates: number[]

    All sample rates (in Hz) that this device supports. For devices that support a range, both the minimum and maximum are included.

    balance: number | null

    Output stereo balance in the range 0.0 (full left)–1.0 (full right), or null if balance control is not available.

    id: number

    The CoreAudio object ID of this device.

    inputChannels: number

    Number of input channels, or 0 if the device has no input.

    inputMuted: boolean

    Whether input is muted. Always false if the device has no mutable input.

    inputVolume: number | null

    Input (microphone) volume scalar in the range 0.01.0, or null if the device has no controllable input volume.

    isInput: boolean

    Whether this device has input streams (can record audio).

    isOutput: boolean

    Whether this device has output streams (can play audio).

    muted: boolean

    Whether output is muted. Always false if the device has no mutable output.

    name: string

    The human-readable name of this device (e.g. "Built-in Output").

    outputChannels: number

    Number of output channels, or 0 if the device has no output.

    sampleRate: number | null

    The current nominal sample rate in Hz (e.g. 44100), or null if unknown.

    transportType: string

    The transport mechanism: "built-in", "usb", "bluetooth", "bluetooth-le", "hdmi", "display-port", "firewire", "airplay", "avb", "thunderbolt", "virtual", "aggregate", "pci", or "unknown".

    uid: string

    The persistent unique identifier for this device.

    volume: number | null

    Output volume scalar in the range 0.01.0, or null if the device has no controllable output volume. Setting null is a no-op.

    Methods

    • Register a listener for a per-device property-change event.

      Parameters

      • listener: (event: string) => void

        A JavaScript function that receives an event name string

      Returns void

    • The current input data source as { id, name }, or null if unavailable.

      Returns Record<string, any> | null

      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.

      Returns Record<string, any> | null

      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.

      Returns Record<string, any>[]

      A dictionary containing the ids and names of all available input data sources

    • All available output data sources as an array of { id, name } objects.

      Returns Record<string, any>[]

      A dictionary containing the ids and names of all available output data sources

    • Remove a previously registered per-device listener.

      Parameters

      • listener: (...args: any[]) => any

        The JavaScript function that was passed to addWatcher(_:)

      Returns void

    • Select an input data source by its numeric ID.

      Parameters

      • sourceID: number

        The id value from inputDataSources()

      Returns boolean

      true on success

    • Select an output data source by its numeric ID.

      Parameters

      • sourceID: number

        The id value from outputDataSources()

      Returns boolean

      true on success

    • Make this device the system alert sound (effect) device.

      Returns boolean

      true on success

    • Make this device the system default input device.

      Returns boolean

      true on success

    • Make this device the system default output device.

      Returns boolean

      true on success