Menu Bar 菜单栏 macos

标本可交互 —— 点点看。Specimen is live — try it.

Anatomy — every part, named解剖 —— 每个部件的名字

  1. 1 App menus (main menu)应用菜单(主菜单) NSApp.mainMenu

    “The File Edit View menus at the top” have a real name: the app's main menu.

    「顶部那排「文件、编辑、显示」菜单」有正式名字:应用的主菜单。

    Prompt fragmentPrompt 片段

    the app's main menu in the macOS menu bar (NSApp.mainMenu): the bold app-name menu followed by File, Edit, View

    macOS 菜单栏里的应用主菜单(NSApp.mainMenu):粗体的应用名菜单,后面跟着 File、Edit、View

  2. 2 Menu bar extra (status item)菜单栏附加项(status item) NSStatusItem

    “The little icon near the clock” is a status item in NSStatusBar.system; SwiftUI calls it MenuBarExtra.

    「时钟旁边的小图标」是 NSStatusBar.system 里的一个 status item;SwiftUI 叫它 MenuBarExtra。

    Prompt fragmentPrompt 片段

    a menu bar extra — an NSStatusItem on the right side of the macOS menu bar (SwiftUI: MenuBarExtra)

    一个菜单栏附加项——macOS 菜单栏右侧的 NSStatusItem(SwiftUI:MenuBarExtra)

  3. 3 Template icon模板图标 NSImage.isTemplate

    The monochrome glyph that recolors itself for light/dark menu bars — a template image, usually an SF Symbol.

    那个会随浅色/深色菜单栏自动变色的单色图形——一张 template image,通常用 SF Symbol。

    Prompt fragmentPrompt 片段

    the status item's icon must be a template image (NSImage.isTemplate = true, ideally an SF Symbol) so macOS recolors it automatically for light and dark menu bars

    status item 的图标必须是 template image(NSImage.isTemplate = true,最好用 SF Symbol),这样 macOS 会为浅色和深色菜单栏自动重新着色

  4. 4 Highlighted state高亮状态 NSStatusBarButton.isHighlighted

    The pale rounded pill behind the icon while its menu or popover is open — the hardest-to-describe pixel on this page.

    菜单或弹出框打开时,图标背后那片浅色圆角底衬——本页最难描述的像素。

    Prompt fragmentPrompt 片段

    the status item's highlighted state: the pale rounded background behind the menu bar icon while its menu is open (NSStatusBarButton.isHighlighted)

    status item 的高亮状态:菜单打开时菜单栏图标背后的浅色圆角背景(NSStatusBarButton.isHighlighted)

  5. 5 Menu菜单 NSMenu

    “The dropdown” from a menu bar icon is an NSMenu — translucent, rounded, vibrancy-backed.

    从菜单栏图标拉下的「那个下拉框」是一个 NSMenu——半透明、圆角、带 vibrancy 底。

    Prompt fragmentPrompt 片段

    the NSMenu dropdown attached to the status item

    挂在 status item 上的 NSMenu 下拉菜单

  6. 6 Selection highlight (menu item)选中高亮(菜单项) NSMenuItem

    “The blue bar when you hover an option”: the menu item's selection highlight, tinted with the system accent color.

    「悬停选项时那条蓝色横条」:菜单项的选中高亮,用系统强调色着色。

    Prompt fragmentPrompt 片段

    the menu item's selection highlight — the accent-colored rounded bar behind an NSMenuItem while it's hovered/selected

    菜单项的选中高亮——NSMenuItem 悬停/选中时背后那条强调色圆角条

  7. 7 Separator item分隔线项 NSMenuItem.separator()

    “The little line between options” is a separator item.

    「选项之间那条小细线」就是分隔线项。

    Prompt fragmentPrompt 片段

    a separator item (NSMenuItem.separator()) dividing the menu into groups

    一个分隔线项(NSMenuItem.separator()),把菜单分成若干组

  8. 8 Key equivalent快捷键(key equivalent) NSMenuItem.keyEquivalent

    “The ⌘Q text on the right side of a menu option” is the item's key equivalent.

    「菜单项右侧的 ⌘Q 字样」就是该项的 key equivalent。

    Prompt fragmentPrompt 片段

    the keyboard shortcut shown at the right edge of the menu item (its key equivalent, NSMenuItem.keyEquivalent, e.g. ⌘Q)

    显示在菜单项右缘的键盘快捷键(即它的 key equivalent,NSMenuItem.keyEquivalent,例如 ⌘Q)

Prompt — paste into your agentPrompt —— 直接粘贴给你的代理

Work on the macOS menu bar: the app's main menu (NSApp.mainMenu) sits on the left after the Apple menu; menu bar extras (NSStatusItem in NSStatusBar.system) sit on the right before the clock. Use the exact part names: status item, its highlighted state, NSMenu, NSMenuItem, separator item.

处理 macOS 菜单栏:应用主菜单(NSApp.mainMenu)在左侧,跟在苹果菜单后面;菜单栏附加项(NSStatusBar.system 里的 NSStatusItem)在右侧、时钟之前。用精确的部件名称:status item、它的 highlighted state、NSMenu、NSMenuItem、separator item。

Debug prompt — when it misbehaves调试 Prompt —— 当它不听话时

Debug my macOS menu bar (NSMenu main menu, NSMenuItem). Rule out: items permanently greyed because their action has no target and nothing in the responder chain implements it; automatic enabling turned off (autoenablesItems) without manual validation; keyboard shortcuts defined but never firing because the item is disabled at validation time; the app menu title coming from the bundle display name, not from code. The symptom:

调试我的 macOS 菜单栏(NSMenu 主菜单、NSMenuItem)。排除以下可能:菜单项永远变灰,因为 action 没有 target,响应链里也没人实现它;关掉了自动启用(autoenablesItems)却没做手动校验;快捷键定义了但从不触发,因为校验时该项是禁用状态;应用菜单的标题来自 bundle 显示名而不是代码。症状是:

In code代码里叫什么

Framework框架Symbol符号Note说明
AppKit NSApp.mainMenu the app's menus on the left左侧的应用菜单
AppKit NSStatusBar.system the icon area on the right右侧的图标区域
SwiftUI MenuBarExtra one right-side icon, macOS 13+右侧单个图标,macOS 13+

See also相关词条