Create custom user interfaces, alerts, dialogs, and file pickers
The hs.ui module provides a set of tools for creating custom user interfaces
in Hammerspoon with SwiftUI-like declarative syntax.
Key Features
Custom Windows: Build custom UI windows with shapes, text, and layouts
Alerts: Display temporary on-screen notifications
Dialogs: Show modal dialogs with custom buttons and callbacks
Text Input: Prompt users for text input
File Pickers: Let users select files or directories
Reactive Colors: Pass an HSColor object to .fill(), .stroke(), or .foregroundColor(),
then call .replaceWithColor() or .replaceWithHex() on it from any callback to re-render the canvas automatically
Reactive Text: Create a string with hs.ui.string(), pass it to .text(),
then call .set() on it to update the displayed content live
Reactive Images: Pass an HSImage object to .image(), then call .replaceWithImage() or .replaceFromFile() on it
to swap the image without rebuilding the window
// Later, interact with dialogs hs.ui.dialog("Shutdown system?") .informativeText("This will close all applications.") .buttons(["Shutdown", "Cancel"]) .onButton((index) => { if (index === 0) { hs.ui.alert("Shutting down...") .duration(3) .show(); } }) .show();
Complete Example: Reactive Hover Card
Demonstrates reactive colors and reactive text together — a single .onHover()
callback updates both the fill color of a shape and the content of a text label:
constcardColor = HSColor.hex("#3498DB"); constcardLabel = hs.ui.string("Hover the card");
hs.ui
Create custom user interfaces, alerts, dialogs, and file pickers
The
hs.uimodule provides a set of tools for creating custom user interfaces in Hammerspoon with SwiftUI-like declarative syntax.Key Features
HSColorobject to.fill(),.stroke(), or.foregroundColor(), then call.replaceWithColor()or.replaceWithHex()on it from any callback to re-render the canvas automaticallyhs.ui.string(), pass it to.text(), then call.set()on it to update the displayed content liveHSImageobject to.image(), then call.replaceWithImage()or.replaceFromFile()on it to swap the image without rebuilding the windowBasic Examples
Simple Alert
Dialog with Buttons
Text Input Prompt
File Picker
Custom Window
Reactive Color on Hover
Reactive Text on Hover
Reactive Image on Click
Complete Example: Status Dashboard
Here's a more complex example showing how to build an interactive status dashboard that combines multiple UI elements:
Complete Example: Reactive Hover Card
Demonstrates reactive colors and reactive text together — a single
.onHover()callback updates both the fill color of a shape and the content of a text label: