API Docs

A keyboard-driven floating chooser panel.

Create via hs.chooser.create(). Configure choices, set callbacks, then call .show().

Choice format

Each choice is a plain object with required text and optional subText, image, valid, and contextMenu fields. All other fields are passed through to the onSelect callback unchanged. Set contextMenu: false on a choice to show no context menu on its row.

{
  text: "Open Safari", subText: "com.apple.Safari",
  image: HSImage.fromAppBundle("com.apple.Safari"), valid: true, myData: 42
}

Context menu

A single right-click menu, set with contextMenu, is shared by every row (except choices with contextMenu: false). When the user picks one of its entries, onContextMenuSelect is called with the row's choice and the menu entry.

chooser.contextMenu = [
  { title: "Open", id: "open" },
  { type: "divider" },
  { title: "Copy bundle ID", id: "copy" }
]
chooser.onContextMenuSelect = (choice, menuItem) => {
  if (menuItem.id === "copy") hs.pasteboard.writeString(choice.subText)
}

Keyboard shortcuts

  • Return — confirm selection
  • Escape — dismiss (calls onSelect with null)
  • ↑ / ↓ — move through results
  • Ctrl-N / Ctrl-P — move through results (alternative to ↑ / ↓)
  • Page Up / Page Down (or Fn-↑ / Fn-↓) — move through results a page (visibleRows rows) at a time
  • Home / End (or Fn-← / Fn-→) — jump to the first / last result
  • Cmd-1 ... Cmd-9, Cmd-0 — instantly select one of the first ten results

Properties

identifier

string

Stable UUID string for this chooser instance.

query

string

The current text in the search field. Setting this from JS updates the display but does not invoke the onQueryChange callback.

placeholder

string

Placeholder text shown in the empty search field (default: "Search...").

searchSubText

boolean

Whether searches match against subText in addition to text (default: false). Only applies when a static choices array is provided.

enableDefaultForQuery

boolean

When true and the query is non-empty but there are no matching choices, onSelect is called with { text: <query> } instead of null (default: false).

selectedRow

number

The zero-based index of the currently highlighted row (-1 when empty).

width

number

Width of the chooser as a fraction of the screen width (default: 0.5 = 50 %).

visibleRows

number

Maximum number of rows visible at once without scrolling (default: 10).

backgroundColor

HSColor

Background color of the chooser panel. When nil (the default), the panel uses the system's translucent glass/material effect.

If you set this to a solid or near-opaque color, also set textColor, subTextColor, and placeholderColor to ensure readable contrast — they are not adjusted automatically.

cornerRadius

number

Corner radius of the chooser panel, in points (default: 14).

borderColor

HSColor

Border color drawn around the chooser panel. When nil (the default), no border is drawn.

borderWidth

number

Width of the border drawn around the chooser panel, in points (default: 1). Has no effect unless borderColor is also set.

textColor

HSColor

Color of each result row's main text. When nil (the default), the system's primary label color is used.

subTextColor

HSColor

Color of each result row's subtext. When nil (the default), the system's secondary label color is used.

queryColor

HSColor

Color of the text the user types into the search field. When nil (the default), the system's primary label color is used.

placeholderColor

HSColor

Color of the placeholder text (and search icon) shown in an empty search field. When nil (the default), the system's secondary label color is used.

selectionColor

HSColor

Background tint of the highlighted row. When nil (the default), a translucent tint of the system accent color is used.

textSize

number

Font size of each result row's main text, in points (default: 14). Changing this also rescales the ⌘-digit shortcut hint shown on the first ten rows, and changes the row height (and therefore the panel height) to fit. Must be a positive, finite number; invalid values are ignored (with a warning logged).

subTextSize

number

Font size of each result row's subtext, in points (default: 12). Changing this also changes the row height (and therefore the panel height) to fit. Must be a positive, finite number; invalid values are ignored (with a warning logged).

querySize

number

Font size of the search field's typed text and placeholder, in points (default: 20). Changing this also rescales the search icon, and changes the search bar height (and therefore the panel height) to fit. Must be a positive, finite number; invalid values are ignored (with a warning logged).

isVisible

boolean

true if the chooser panel is currently on screen.

onSelect

function | null

Called when the user confirms a selection, or null to remove the handler.

The argument is the chosen row object (the original dict you passed to setChoices, with text, subText, image, valid, and any custom fields intact). The argument is null when dismissed (Escape).

onQueryChange

function | null

Called on every keystroke with the new query string, or null to remove the handler.

Use this to debounce expensive searches or trigger async data fetching.

onSelectionChange

function | null

Called when the selected row changes while the chooser is visible, or null to remove the handler.

Use this to show something that depends on the selected row, such as a preview, and keep it up to date as the user moves through the rows.

The arguments are the new selectedRow and the row object (same shape as onSelect), or null for the item when no rows match the query. It is called once when the chooser is shown, then whenever the selection moves to a different row, or the row it is on changes to a different choice: arrow keys, Page Up/Down, Home/End, a click, a new query, new choices, or setting selectedRow from JavaScript.

onShow

function | null

Called after the panel becomes visible, or null to remove the handler.

onHide

function | null

Called after the panel is hidden (for any reason: selection, Escape, or hide()), or null to remove the handler.

onInvalid

function | null

Called when the user activates a row whose valid field is false, or null to remove the handler. The chooser stays open; the argument is the row dict (same shape as onSelect). If unset, activating an invalid row is silently ignored.

contextMenu

any[]

The right-click menu shown for every row (default: [], no menu).

Each entry is either { title: "..." } for a menu item, or { type: "divider" } for a separator. Any other fields on an entry (e.g. an id) are passed back to onContextMenuSelect unchanged, so one handler can tell the entries apart.

Rows whose choice has contextMenu: false show no menu, e.g. for a "Clear history" row.

onContextMenuSelect

function | null

Called when the user picks an entry from the contextMenu, or null to remove the handler.

choice is the row that was right-clicked (same shape as onSelect's argument) and menuItem is the contextMenu entry that was picked, with any custom fields intact. The chooser stays open.

Methods

setChoices(choices) -> HSChooser

Set the choices list. Pass a static array or a function:

  • Array — the chooser filters it automatically as the user types.
  • Function — called with the current query string on every refreshChoices() and on show. The function is responsible for filtering; the chooser displays all items it returns.
setChoices(choices) -> HSChooser
Name Type Description
choices JSValue An array of choice objects, or a function (query) => [...]
HSChooser
Self for chaining
// Static
chooser.setChoices([{text: "Foo"}, {text: "Bar"}])

// Dynamic
chooser.setChoices(q => items.filter(i => i.text.toLowerCase().includes(q.toLowerCase())))

refreshChoices() -> HSChooser

Re-apply filtering (static choices) or re-invoke the choices function (dynamic). Call after updating an external data source in an async onQueryChange handler.

refreshChoices() -> HSChooser
HSChooser
Self for chaining
chooser.refreshChoices()

show() -> HSChooser

Show the chooser.

show() -> HSChooser
HSChooser
Self for chaining
A shown chooser, and its callbacks, stay alive until it's hidden, even if you don't keep a reference to it
chooser.show()

hide() -> HSChooser

Hide the chooser without making a selection. Restores focus to the previously active window.

hide() -> HSChooser
HSChooser
Self for chaining
chooser.hide()

select(row) -> HSChooser

Programmatically confirm a selection.

Omit row to confirm the currently highlighted row. Fires onSelect (or onInvalid for rows with valid: false) and hides the chooser.

select(row) -> HSChooser
Name Type Description
row JSValue Zero-based row index, or omit to use the current selection.
HSChooser
Self for chaining
chooser.select()     // confirm highlighted row
chooser.select(2)    // confirm row at index 2

selectedRowContents(row) -> [String: Any]

Returns the dict for the highlighted row, or for a specific row by index. Returns null if the index is out of range or no choices are set.

selectedRowContents(row) -> [String: Any]
Name Type Description
row JSValue Zero-based row index, or omit to query the highlighted row.
[String: Any]
The row dict ({ text, subText?, image?, valid, ...extras }) or null.
const item = chooser.selectedRowContents()
const item = chooser.selectedRowContents(2)