hs.sound
ModulePlay 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.
Declaration
hs.sound.fromFile(path) -> HSSound
Parameters
| Name | Type | Description |
|---|---|---|
| path | string | The absolute path to an audio file (AIFF, WAV, MP3, CAF, etc.). |
Returns
HSSound
An `HSSound` object, or `null` on failure.
Example
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.
Declaration
hs.sound.named(name) -> HSSound
Parameters
| Name | Type | Description |
|---|---|---|
| name | string | The name of a system sound, e.g. `"Basso"` or `"Glass"`. |
Returns
HSSound
An `HSSound` object, or `null` on failure.
Example
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`.
Declaration
hs.sound.systemSounds() -> string[]
Returns
string[]
A sorted array of sound name strings.
Example
console.log(hs.sound.systemSounds())
// ["Basso", "Blow", "Bottle", "Frog", "Funk", "Glass", ...]