macOS Dock menu
Populate the Dock right-click menu of a macOS app with items, submenus, and separators, and handle clicks from Kotlin.
launcher-macos fills the Dock right-click menu of a macOS app with items, submenus, separators,
and disabled entries, and calls you back on the UI thread when the user clicks one.
launcher-macosGradle plugin: RecommendedWindow runtime: Not neededUnder ./gradlew run the Dock tile belongs to java; test from a packaged app.dependencies {
implementation("dev.nucleusframework:nucleus.launcher-macos:3.0.0")
}Populate the Dock menu
Each item carries a numeric id, which the listener receives:
MacOsDockMenu.setDockMenu(listOf(
DockMenuItem(id = 1, title = "New Window"),
DockMenuItem.separator(id = 2),
DockMenuItem(
id = 3,
title = "Recent",
children = listOf(
DockMenuItem(id = 31, title = "project.kt"),
DockMenuItem(id = 32, title = "build.gradle.kts"),
),
),
))
MacOsDockMenu.listener = DockMenuListener { id ->
when (id) {
1 -> openNewWindow()
in 30..39 -> openRecent(id)
}
}clearDockMenu() restores the default Dock menu. Every method does nothing off macOS or when
the native library fails to load; check isAvailable first. The Dock renders text only, so item
images are not supported.
Changed in 3.0
The listener now runs on the host UI thread instead of the Swing EDT. Under
nucleusApplication that is the thread Compose uses, so you can write Compose state from it
directly. See Threading and
Migrate from 2.x.
Test from a packaged build or runDistributable. Under ./gradlew run, the Dock tile belongs to
the java launcher, which has no bundle identifier.
API reference
| Symbol | Notes |
|---|---|
MacOsDockMenu.isAvailable | false off macOS or when the native library failed to load. |
MacOsDockMenu.listener: DockMenuListener? | One global listener. Dispatch on id inside it. |
MacOsDockMenu.setDockMenu(items) | Replaces the menu. |
MacOsDockMenu.clearDockMenu() | Removes the menu; the OS default returns. |
DockMenuItem(id, title = "", enabled = true, children = emptyList()) | id must be > 0. Non-empty children makes a submenu. |
DockMenuItem.separator(id) | A separator. |
DockMenuListener.onItemClicked(itemId: Int) | fun interface, called on the host UI thread. |
What's next
- Taskbar progress: progress and attention requests on the Dock icon.
- Deep links: receive
myapp://URLs through Apple Events. - Windows taskbar: jump lists and thumbnail toolbars.
Last updated on