HSMenuBarItem
TypeObject representing a macOS system menu bar item.
Create instances with hs.menubar.create().
Properties
Methods
setTitle(title) -> None
Set the text title displayed in the menu bar
Declaration
setTitle(title) -> None
Parameters
| Name | Type | Description |
|---|---|---|
| title | JSValue | Text to display, or null to remove the title |
Returns
None
Example
const item = hs.menubar.create()
item.setTitle("Hello")
setIcon(image) -> None
Set the icon displayed in the menu bar
Declaration
setIcon(image) -> None
Parameters
| Name | Type | Description |
|---|---|---|
| image | JSValue | An HSImage object, or null to remove the icon |
Returns
None
Example
const item = hs.menubar.create()
item.setIcon(HSImage.fromSymbol("star.fill"))
setTooltip(tooltip) -> None
Set the tooltip shown when hovering over the menu bar item
Declaration
setTooltip(tooltip) -> None
Parameters
| Name | Type | Description |
|---|---|---|
| tooltip | JSValue | Tooltip text, or null to remove the tooltip |
Returns
None
Example
const item = hs.menubar.create()
item.setTooltip("My menu bar item")
setClickCallback(fn) -> None
Set a callback invoked when the item is clicked (only fires when no menu is set)
Declaration
setClickCallback(fn) -> None
Parameters
| Name | Type | Description |
|---|---|---|
| fn | JSValue | A function to call on click, or null to remove the callback |
Returns
None
Example
const item = hs.menubar.create()
item.setTitle("Click me")
item.setClickCallback(() => console.log("clicked!"))
setMenu(menuOrFn) -> None
Set the menu for this item. Pass an array of menu item objects for a static menu,
or a function that returns an array for a dynamic menu populated each time it opens.
Declaration
setMenu(menuOrFn) -> None
Parameters
| Name | Type | Description |
|---|---|---|
| menuOrFn | JSValue | Array of menu item objects, a function returning such an array, or null to remove the menu |
Returns
None
Example
const item = hs.menubar.create()
item.setTitle("Menu")
item.setMenu([
{ title: "Option A", fn: () => console.log("A") },
{ title: "-" },
{ title: "Option B", checked: true, fn: () => console.log("B") }
])
hide() -> None
Remove this item from the menu bar. The item is retained and can be shown again with show().
Declaration
hide() -> None
Returns
None
Example
const item = hs.menubar.create()
item.hide()
show() -> None
Show this item in the menu bar.
Declaration
show() -> None
Returns
None
Example
item.show()
isVisible() -> boolean
Check if this item is currently visible in the menu bar.
Declaration
isVisible() -> boolean
Returns
boolean
true if the item is visible in the menu bar
Example
const visible = item.isVisible()