HSUIAlert
TypeHSUIAlert
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
Declaration
font(font) -> HSUIAlert
Parameters
| Name | Type | Description |
|---|---|---|
| font | HSFont | An HSFont object (e.g., `HSFont.headline()`) |
Returns
HSUIAlert
Self for chaining
Example
hs.ui.alert("Hello").font(HSFont.headline()).show()
duration(seconds) -> HSUIAlert
Set how long the alert is displayed
Declaration
duration(seconds) -> HSUIAlert
Parameters
| Name | Type | Description |
|---|---|---|
| seconds | number | Duration in seconds (default: 5.0) |
Returns
HSUIAlert
Self for chaining
Example
hs.ui.alert("Hello").duration(3).show()
padding(points) -> HSUIAlert
Set the padding around the alert text
Declaration
padding(points) -> HSUIAlert
Parameters
| Name | Type | Description |
|---|---|---|
| points | number | Padding in points (default: 20) |
Returns
HSUIAlert
Self for chaining
Example
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.
Declaration
position(dict) -> HSUIAlert
Parameters
| Name | Type | Description |
|---|---|---|
| dict | {[key: string]: any} | Dictionary with `x` and `y` coordinates |
Returns
HSUIAlert
Self for chaining
Example
hs.ui.alert("Hello").position({x: 100, y: 100}).show()
show() -> HSUIAlert
Show the alert
Declaration
show() -> HSUIAlert
Returns
HSUIAlert
Self for chaining (can store reference to close manually)
Example
hs.ui.alert("Hello").show()
close() -> None
Close the alert immediately
Declaration
close() -> None
Returns
None
Example
const a = hs.ui.alert("Hello").show()
a.close()