HSUIDialog
Type
HSUIDialog
A modal dialog with customizable buttons
Shows a blocking dialog with a message, optional informative text, and custom buttons. Use the callback to respond to button presses.
Example
hs.ui.dialog("Save changes?")
.informativeText("Your document has unsaved changes.")
.buttons(["Save", "Don't Save", "Cancel"])
.onButton((index) => {
if (index === 0) {
print("Saving...");
} else if (index === 1) {
print("Discarding changes...");
}
})
.show();
Properties
This type has no properties.
Methods
informativeText(text)
Set additional informative text below the main message
Hammerspoon 2/Modules/hs.ui/Dialogs/HSUIDialog.swift:39
Parameters
-
textstringThe informative text
Returns
HSUIDialog - Self for chaining
buttons(labels)
Set custom button labels
Hammerspoon 2/Modules/hs.ui/Dialogs/HSUIDialog.swift:44
Parameters
-
labelsstring[]Array of button labels (default: ["OK"])
Returns
HSUIDialog - Self for chaining
style(style)
Set the dialog style
Hammerspoon 2/Modules/hs.ui/Dialogs/HSUIDialog.swift:49
Parameters
-
stylestringStyle name (e.g., "informational", "warning", "critical")
Returns
HSUIDialog - Self for chaining
onButton(callback)
Set the callback for button presses
Hammerspoon 2/Modules/hs.ui/Dialogs/HSUIDialog.swift:54
Parameters
-
callbackJSValueFunction receiving button index (0-based)
Returns
HSUIDialog - Self for chaining
show()
Show the dialog
Hammerspoon 2/Modules/hs.ui/Dialogs/HSUIDialog.swift:58
Parameters
None
Returns
HSUIDialog - Self for chaining
close()
Close the dialog programmatically
Hammerspoon 2/Modules/hs.ui/Dialogs/HSUIDialog.swift:61
Parameters
None
Returns
Nothing