Allow or prevent the user from resizing the window
Enabled by default. Only has a visual effect when .titled(true) is also set.
Pass false to prevent the user from resizing the window
Self for chaining
Set the aspect ratio mode for an image
"fit" (scales to fit within frame) or "fill" (scales to fill frame)
Self for chaining
Set the window's background color
A hex color string (e.g. "#FF0000") or an HSColor object
Self for chaining
Add a button element
or an HSString object (from hs.ui.string()) for reactive text
The button label — a plain JS string for static text,
Self for chaining (apply .fill(), .cornerRadius(), .font(),
Show or hide the close button on the window
Requires .titled(true) to be visible. Enabled by default.
Pass false to hide the close button
Self for chaining
Round the corners of a shape
Corner radius in points
Self for chaining
Destroy the window
Fill a shape with a color
A hex color string (e.g. "#FF0000") or an HSColor object
Self for chaining
Set the font for a text element
An HSFont object (e.g., HSFont.title())
Self for chaining
Set the text color
A hex color string (e.g. "#FF0000") or an HSColor object
Self for chaining
Set the frame (size) of an element
Dictionary with w and/or h (can be numbers or percentage strings like "50%")
Self for chaining
Hide the window (keeps it in memory)
Begin a horizontal stack (elements arranged left to right)
Self for chaining (call end() when done)
Add an image element
Image as HSImage object
Self for chaining (apply modifiers like resizable(), aspectRatio(), frame())
Set the window stacking level Controls where this window sits in the macOS window hierarchy.
The level name
Self for chaining
Show or hide the miniaturize (yellow) button on the window
Requires .titled(true) to be visible. Enabled by default.
Pass false to hide the miniaturize button
Self for chaining
Set a callback to fire when the element is clicked
A JavaScript function to call on click
Self for chaining
Set a callback to fire after the window is destroyed via destroy()
Only fires when destroy() is called explicitly — whether directly, or from
within an onHide() handler. It does not fire when the user clicks the macOS
close button by itself; that only hides the window, so use onHide() to react to
the button click, and call destroy() from that handler if you also want to
release the window.
A JavaScript function called after the window is destroyed
Self for chaining
Set a callback to fire when the window is hidden
Fires when hide() is called, and when the user clicks the macOS close
button — clicking that button only hides the window from Hammerspoon's
perspective (see the class-level note above), so this is the callback that reacts
to it. Does not fire when the window is destroyed via destroy() — use
onDestroy() for that.
A JavaScript function called after the window is hidden
Self for chaining
Set a callback to fire when the cursor enters or leaves the element
A JavaScript function called with true when the cursor enters and false when it leaves
Self for chaining
Set a callback to fire after the window is shown
A JavaScript function called after the window becomes visible
Self for chaining
Set the opacity of an element
Opacity from 0.0 (transparent) to 1.0 (opaque)
Self for chaining
Add padding around a layout container
Padding in points
Self for chaining
Set spacing between elements in a stack
Spacing in points
Self for chaining
Add a stroke (border) to a shape
A hex color string (e.g. "#FF0000") or an HSColor object
Self for chaining
Add a text element
or an HSString object (from hs.ui.string()) for reactive text
The text to display — a plain JS string for static text,
Self for chaining (apply modifiers like font(), foregroundColor())
Show or hide the window's title bar
By default windows have a title bar. Pass false to create a borderless window.
.closable(), .miniaturizable(), and .allowResize() only take visual effect
when the window is titled.
Pass false to make the window borderless
Self for chaining
Add a video element
Renders a SwiftUI VideoPlayer for the given HSVideo. Keep a reference to the
HSVideo object to control playback (play(), pause(), seek(), volume) after
the window is shown.
Video as an HSVideo object
Self for chaining (apply modifiers like frame(), opacity())
Begin a vertical stack (elements arranged top to bottom)
Self for chaining (call end() when done)
Embed a web browser element created with hs.ui.webview() (macOS 26+)
The element fills the available space in the window layout.
Keep a reference to the element to call navigation methods after the window is shown.
A UIWebView created via hs.ui.webview()
Self for chaining
Set the text shown in the window's title bar
Only visible when .titled(true) is set (the default).
The title bar text
Self for chaining
HSUIWindow
A custom window with declarative UI building*
HSUIWindowallows you to create custom windows with a SwiftUI-like declarative syntax. Build interfaces using shapes, text, images, and layout containers.onHide()callback, if you have one configured) — it does not destroy the window while you hold a reference to it in JavaScript. Calldestroy()explicitly (for example from within anonHide()handler) if you want to release it. SeeonShow(),onHide(), andonDestroy()below for the full set of lifecycle callbacks.Building UI Elements
Modifying Elements
Examples
Simple window with text and shapes:*
Window with image:*