API Docs

Play audio from files on disk or from the system's built-in sound library.

Types

This module provides the following types:

Properties

This module has no properties.

Methods

hs.sound.fromFile(path) -> HSSound

Loads an audio file from the given path and returns a sound object. Returns `null` if the file cannot be loaded.
hs.sound.fromFile(path) -> HSSound
Name Type Description
path string The absolute path to an audio file (AIFF, WAV, MP3, CAF, etc.).
HSSound
An `HSSound` object, or `null` on failure.
const s = hs.sound.fromFile("/Users/me/sounds/alert.aiff")
if (s) s.play()

hs.sound.named(name) -> HSSound

Creates a sound object for a built-in system sound by name. Returns `null` if no sound with that name can be found. Use `hs.sound.systemSounds()` to discover available names.
hs.sound.named(name) -> HSSound
Name Type Description
name string The name of a system sound, e.g. `"Basso"` or `"Glass"`.
HSSound
An `HSSound` object, or `null` on failure.
hs.sound.named("Basso").play()

hs.sound.systemSounds() -> string[]

Returns a sorted array of all available system sound names. These names can be passed directly to `hs.sound.named()`. Scans `/System/Library/Sounds`, `/Library/Sounds`, and `~/Library/Sounds`.
hs.sound.systemSounds() -> string[]
string[]
A sorted array of sound name strings.
console.log(hs.sound.systemSounds())
// ["Basso", "Blow", "Bottle", "Frog", "Funk", "Glass", ...]