hammerspoon2-docs
    Preparing search index...

    Class HSMenuBarItem

    Object representing a macOS system menu bar item. Create instances with hs.menubar.create().

    Index

    Constructors

    Properties

    title: string | null

    Get or set the menu item's title.

    titleColor: HSColor | null

    Get or set the colour of the menu item's title text, or null to use the menu bar's standard text colour.

    Methods

    • Permanently remove this item from the menu bar and release all resources. After calling destroy(), the item is no longer usable. This is called automatically on hs.reload(). Use hide() instead if you only want to temporarily remove the item without freeing it.

      Returns void

    • Remove this item from the menu bar. It can be shown again with show() while you keep a reference to it.

      Returns void

    • Check if this item is currently visible in the menu bar.

      Returns boolean

      true if the item is visible in the menu bar

    • Immediately open a menu below this item, independently of any menu set with setMenu(). This is intended to be called from a click callback, so that a single item can perform an action on one kind of click and offer a menu on another. The menu item objects are the same as for setMenu(). If the item is hidden, the menu opens at the mouse pointer instead.

      Parameters

      • entries: Record<string, any>[]

        Array of menu item objects

      Returns void

    • Set a callback invoked when the item is clicked with any mouse button (only fires when no menu is set). from 1 (so a mouse's fourth and fifth buttons are "button4" and "button5"). A Ctrl-click, the standard macOS secondary click, is reported as "right" (and modifiers still includes "ctrl"). hs.eventtap.currentModifiers() (e.g. ["cmd", "leftCmd"]). To offer a menu alongside a click action, leave the menu unset and call popUpMenu() from this callback.

      Parameters

      • fn: ((button: string, modifiers: string[]) => void) | null

        A function to call on click, or null to remove the callback

      Returns void

    • Set the icon displayed in the menu bar

      Parameters

      • image: HSImage | null

        An HSImage object, or null to remove the icon

      Returns void

    • 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. The function receives one argument: the modifier keys held when the menu opened, in the same form as hs.eventtap.currentModifiers(). While a menu is set, clicking the item opens the menu and the click callback is not called.

      Parameters

      • menuOrFn: Record<string, any>[] | ((modifiers: string[]) => Record<string, any>[]) | null

        Array of menu item objects, a function returning such an array, or null to remove the menu

      Returns void

    • Set the tooltip shown when hovering over the menu bar item

      Parameters

      • tooltip: string | null

        Tooltip text, or null to remove the tooltip

      Returns void

    • Show this item in the menu bar.

      Returns void

      A visible item, and its callbacks, stay in the menu bar until it's hidden or destroyed, even if you don't keep a reference to it