hs.notify
ModuleModule for creating and displaying macOS system notifications.
macOS notifications require user permission before they will appear. Request it once
(typically at startup) via hs.permissions.requestNotifications() and it will be
remembered across sessions:
hs.permissions.requestNotifications().then(granted => {
if (granted) hs.notify.show("Hammerspoon", "Notifications are enabled!")
})
Quick notification
// Fire and forget
hs.notify.show("Build complete", "Your project compiled successfully.")
// With a callback invoked when the user interacts
hs.notify.show("Build complete", "Click to view the log.", (response) => {
console.log("User tapped:", response.actionIdentifier)
})
Rich notification
const n = hs.notify.create({
title: "New message",
subtitle: "From Alice",
body: "Are you free tonight?",
sound: true,
threadIdentifier: "messages-alice",
actions: [
{ identifier: "REPLY", title: "Reply", textInput: true,
textInputButtonTitle: "Send", textInputPlaceholder: "Type a reply…" },
{ identifier: "DISMISS", title: "Dismiss", destructive: true }
],
callback: (response) => {
if (response.actionIdentifier === "REPLY") {
console.log("Reply text:", response.userText)
}
}
})
n.send()
// Later, if needed:
n.withdraw()
The callback function receives an HSNotificationResponse, and create() takes an
HSNotificationOptions.
Triggers
Pass a trigger object in create()'s options to schedule the notification instead of delivering it
Time interval — deliver after a fixed delay in seconds (minimum 60 s):
trigger: { type: "timeInterval", interval: 300 }
Calendar — deliver at a specific date/time. Provide either a JS Date object or individual
date-component keys; any omitted component matches every value:
// At a specific moment
trigger: { type: "calendar", date: new Date("2026-06-01T09:00:00") }
// At 09:00 on the next day that matches (e.g. next Monday, weekday 2)
trigger: { type: "calendar", weekday: 2, hour: 9, minute: 0 }
Supported component keys: year, month, day, hour, minute, second, weekday.
Types
This module provides the following types:
Object Types
Plain JavaScript objects that this module's methods and properties take or return:
HSNotificationResponse
How the user interacted with a notification, passed to its callback
| Field | Type | Description |
|---|---|---|
| actionIdentifier | string | "DEFAULT" when the user tapped the notification body; "DISMISS" when dismissed (if .customDismissAction is set); otherwise the action's identifier |
| userText optional | string | Text entered in a textInput action; only present when applicable |
| userInfo | Record<string, any> | The userInfo object originally passed to create(), if any |
| notificationId | string | The notification's unique identifier |
HSNotificationOptions
The options for hs.notify.create()
| Field | Type | Description |
|---|---|---|
| title | string | The bold heading line |
| subtitle optional | string | A second line shown beneath the title |
| body optional | string | The main message body |
| sound optional | boolean | string | true (the default) for the default sound, false for none, or the name of an .aiff file |
| badge optional | number | Value to show on the app icon badge |
| threadIdentifier optional | string | Groups related notifications visually in Notification Center |
| userInfo optional | Record<string, any> | Arbitrary payload passed back to the callback |
| interruptionLevel optional | "passive" | "active" | "timeSensitive" | Controls Focus/DND behaviour. Defaults to "active" |
| trigger optional | {type: "timeInterval", interval: number} | {type: "calendar", date?: Date, year?: number, month?: number, day?: number, hour?: number, minute?: number, second?: number, weekday?: number} | When to deliver the notification (see the module documentation). Omit for immediate delivery |
| actions optional | HSNotificationAction[] | Action buttons |
| callback optional | (response: HSNotificationResponse) => void | Invoked when the user interacts with the notification |
HSNotificationAction
An action button of a notification
| Field | Type | Description |
|---|---|---|
| identifier | string | Unique identifier passed to the callback |
| title | string | Button label |
| destructive optional | boolean | Renders the title in a destructive (red) style. Defaults to false |
| foreground optional | boolean | Brings Hammerspoon to the foreground when tapped. Defaults to false |
| textInput optional | boolean | Converts this action to an inline text-reply button. Defaults to false |
| textInputButtonTitle optional | string | Label on the reply send button (requires textInput: true). Defaults to "Send" |
| textInputPlaceholder optional | string | Placeholder shown in the text field (requires textInput: true). Defaults to "" |
Properties
This module has no properties.
Methods
hs.notify.show(title, body, callback) -> None
Display a notification immediately.
hs.notify.show(title, body, callback) -> None
| Name | Type | Description |
|---|---|---|
| title | string | The notification title |
| body | string | The notification body text |
| callback optional | (response: HSNotificationResponse) => void | Optional function called when the user taps the notification. |
hs.notify.show("Build complete", "Your project compiled successfully.")
hs.notify.create(options) -> HSNotification
Create a richly configured notification without sending it yet.
hs.notify.create(options) -> HSNotification
| Name | Type | Description |
|---|---|---|
| options | HSNotificationOptions | How to configure the notification |
HSNotification object. Call .send() on it to deliver the notification.const n = hs.notify.create({ title: "Hello", body: "World" })
n.send()
hs.notify.removeAllDelivered() -> None
Remove all delivered Hammerspoon notifications from Notification Center.
hs.notify.removeAllDelivered() -> None
hs.notify.removeAllDelivered()
hs.notify.removeAllPending() -> None
Cancel all pending (not yet delivered) Hammerspoon notifications.
hs.notify.removeAllPending() -> None
hs.notify.removeAllPending()