hammerspoon2-docs
    Preparing search index...

    Class HSCamera

    A camera device attached to the system. Obtain instances via the hs.camera module — do not instantiate directly.

    const cam = hs.camera.all()[0]
    console.log(cam.name + " uid=" + cam.uid + " inUse=" + cam.isInUse)
    const cam = hs.camera.all()[0]
    const fn = (isInUse) => {
    console.log(cam.name + " is now " + (isInUse ? "in use" : "not in use"))
    }
    cam.addWatcher(fn)
    // later…
    cam.removeWatcher(fn)
    const cam = hs.camera.all()[0]
    cam.captureImage()
    .then(img => img.saveToFile("/tmp/shot.png"))
    .catch(err => console.error("Capture failed: " + err))
    Index

    Constructors

    Properties

    isInUse: boolean

    Whether this camera is currently being used by any application. Queries the underlying CoreMediaIO device state each time it is read.

    name: string

    The human-readable name of this camera (e.g. "FaceTime HD Camera").

    typeName: string

    The type name for JavaScript introspection. Always "HSCamera".

    uid: string

    The persistent unique identifier for this camera.

    Methods

    • Register a listener that fires whenever this camera's in-use state changes. The listener receives one argument: a boolean that is true when the camera starts being used and false when it is released.

      Parameters

      • listener: (isInUse: boolean) => void

        A JavaScript function called with true when the camera starts being used and false when released

      Returns void

    • Capture a still image from this camera. Camera permission must be granted via hs.permissions.requestCamera() before calling this method. The returned HSImage can be saved, displayed in a UI element, or passed to other image-processing APIs.

      Returns Promise<HSImage>

      A Promise that resolves to an HSImage, or rejects on error

    • Remove a previously registered per-camera in-use listener.

      Parameters

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

        The function originally passed to addWatcher(_:)

      Returns void