hs.menubar
ModuleModule for creating and managing macOS system menu bar items.
Menu bar items appear in the right side of the macOS menu bar (alongside the clock, Wi-Fi icon, etc.). Each item can display a title, an icon, or both, and can open a menu or invoke a callback when clicked.
Creating a simple title item
const item = hs.menubar.create()
item.setTitle("Hello")
item.setClickCallback(() => console.log("clicked!"))
Creating an icon item with a static menu
const item = hs.menubar.create()
item.setIcon(HSImage.fromSymbol("star.fill"))
item.setTooltip("My automation")
item.setMenu([
{ title: "Reload config", fn: () => hs.reload() },
{ title: "-" },
{ title: "Remove from menubar", fn: () => item.hide() }
])
Creating an item with a dynamic menu
const item = hs.menubar.create()
item.setTitle("Dynamic")
item.setMenu(() => [
{ title: "Time: " + new Date().toLocaleTimeString() },
{ title: "-" },
{ title: "Remove from menubar", fn: () => item.hide() }
])
Types
This module provides the following types:
Properties
This module has no properties.
Methods
hs.menubar.create(hidden) -> HSMenuBarItem
Create a new menu bar item
Declaration
hs.menubar.create(hidden) -> HSMenuBarItem
Parameters
| Name | Type | Description |
|---|---|---|
| hidden | boolean | Pass true to create the item hidden (not shown in the menu bar). Defaults to false (immediately visible). |
Returns
HSMenuBarItem
A new HSMenuBarItem
Example
const item = hs.menubar.create()
const hidden = hs.menubar.create(true) // not shown yet
hidden.setTitle("Ready")
hidden.show()