HSMenuBarItem
TypeObject representing a macOS system menu bar item.
Create instances with hs.menubar.create().
Properties
Methods
setIcon(image) -> None
Set the icon displayed in the menu bar
Declaration
setIcon(image) -> None
Parameters
| Name | Type | Description |
|---|---|---|
| image | HSImage | 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 | string | 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 | function | A function to call on click, or null to remove the callback |
Returns
None
Example
const item = hs.menubar.create()
item.title = "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.title = "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()