API Docs

HSUIAlert

A temporary on-screen notification

Displays a message that automatically fades out after a specified duration. Without an explicit .position(), multiple alerts stack vertically and stay centered as they appear and disappear. With .position(), the alert appears at the given coordinates regardless of other alerts.

Example

hs.ui.alert("Task completed!")
    .font(HSFont.headline())
    .duration(5)
    .padding(30)
    .show();

Properties

This type has no properties.

Methods

font(font) -> HSUIAlert

Set the font for the alert text
font(font) -> HSUIAlert
Name Type Description
font HSFont An HSFont object (e.g., `HSFont.headline()`)
HSUIAlert
Self for chaining
hs.ui.alert("Hello").font(HSFont.headline()).show()

duration(seconds) -> HSUIAlert

Set how long the alert is displayed
duration(seconds) -> HSUIAlert
Name Type Description
seconds number Duration in seconds (default: 5.0)
HSUIAlert
Self for chaining
hs.ui.alert("Hello").duration(3).show()

padding(points) -> HSUIAlert

Set the padding around the alert text
padding(points) -> HSUIAlert
Name Type Description
points number Padding in points (default: 20)
HSUIAlert
Self for chaining
hs.ui.alert("Hello").padding(30).show()

position(dict) -> HSUIAlert

Set a custom position for the alert When a position is set, the alert is shown at those coordinates and will not be stacked with other alerts. Coordinates are in points from the top-left of the visible screen area (below the menu bar), with y increasing downward.
position(dict) -> HSUIAlert
Name Type Description
dict {[key: string]: any} Dictionary with `x` and `y` coordinates
HSUIAlert
Self for chaining
hs.ui.alert("Hello").position({x: 100, y: 100}).show()

show() -> HSUIAlert

Show the alert
show() -> HSUIAlert
HSUIAlert
Self for chaining (can store reference to close manually)
hs.ui.alert("Hello").show()

close() -> None

Close the alert immediately
close() -> None
None
const a = hs.ui.alert("Hello").show()
a.close()