API Docs

Module 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.title = "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.title = "Dynamic"
item.setMenu(() => [
    { title: "Time: " + new Date().toLocaleTimeString() },
    { title: "-" },
    { title: "Remove from menubar", fn: () => item.hide() }
])

Types

This module provides the following types:

Object Types

Plain JavaScript objects that this module's methods and properties take or return:

HSMenuShortcut

A keyboard shortcut spelled out, for the shortcut of a menu item. Modifier and key names are the same as for hs.hotkey.bind()

Field Type Description
mods optional string[] The modifier keys, e.g. ["cmd", "shift"]. Leave out for no modifiers
key string | number The key: a numeric virtual key code, a character, a key name such as "return", "delete", "left" or "f5", or the symbol a menu draws for it such as "↩"

HSMenuItem

An item in a menu built from JavaScript, for HSMenuBarItem.setMenu(), HSMenuBarItem.popUpMenu() and hs.dockicon.setMenu()

Field Type Description
title string The item's label. Use "-" for a separator line
fn optional () => void Called when the item is chosen
checked optional boolean If true, a checkmark is shown next to the item
disabled optional boolean If true, the item is greyed out and cannot be chosen
tooltip optional string Shown when hovering over the item
color optional HSColor | string The colour of the item's title, as an HSColor or a hex string
icon optional HSImage An icon shown to the left of the title
menu optional HSMenuItem[] The items of a submenu
shortcut optional string | HSMenuShortcut A keyboard shortcut shown at the right-hand side of the item: a string of modifier symbols (⌘ ⇧ ⌥ ⌃) followed by one key, as the menu shows it ("⇧⌘N", or just "F" for no modifiers), or the modifiers and key spelled out. It only works while the menu is open

Properties

This module has no properties.

Methods

hs.menubar.create(hidden) -> HSMenuBarItem

Create a new menu bar item

hs.menubar.create(hidden) -> HSMenuBarItem
Name Type Description
hidden optional boolean Pass true to create the item hidden (not shown in the menu bar). Defaults to false (immediately visible).
A new HSMenuBarItem
A visible item stays in the menu bar, with its callbacks, until it's hidden or destroyed, even if you don't keep a reference to it
const item = hs.menubar.create()
const hidden = hs.menubar.create(true)  // not shown yet
hidden.title = "Ready"
hidden.show()