Back to prompts
CodingChatGPTClaudeGemini

macOS Menu Bar App Generator

Build a complete macOS menu bar (status bar) app with SwiftUI, including popover UI, keyboard shortcuts, and launch-at-login support.

Prompt Template

You are an expert macOS developer. Help me build a menu bar (status bar) app for macOS using SwiftUI.

**App Purpose:** [e.g., "A clipboard history manager" or "A quick note-taking widget"]
**What the popover should show:** [describe the UI that appears when clicking the menu bar icon]
**Key Features:**
- [Feature 1]
- [Feature 2]
- [Feature 3]
**Global Hotkey:** [optional — e.g., "⌘⇧V to toggle the popover"]
**Persistent Data:** [what needs to be saved between launches]
**Background Tasks:** [any monitoring, polling, or event listening needed]

Please provide:
1. **App entry point** — @main struct using MenuBarExtra (macOS 13+) with .window or .popover style
2. **Menu bar icon** — SF Symbol choice + dynamic states (e.g., different icon when active)
3. **Popover/window view** — full SwiftUI view with proper sizing and styling
4. **Data persistence** — UserDefaults, SwiftData, or file-based as appropriate
5. **Launch at Login** — using SMAppService (macOS 13+)
6. **Global keyboard shortcut** registration (if requested)
7. **Proper lifecycle** — handle popover show/hide, app activation without dock icon
8. **Info.plist** settings — LSUIElement for hiding dock icon, any required entitlements
9. **Complete working code** — should compile and run as-is in a new Xcode project

Example Output

import SwiftUI

import ServiceManagement

@main

struct ClipboardHistoryApp: App {

@State private var clipboardItems: [ClipItem] = []

var body: some Scene {

MenuBarExtra {

ClipboardPopoverView(items: $clipboardItems)

.frame(width: 320, height: 420)

} label: {

Label("Clipboard", systemImage: clipboardItems.isEmpty ? "clipboard" : "clipboard.fill")

}

.menuBarExtraStyle(.window)

Settings {

SettingsView()

}

}

}

struct ClipboardPopoverView: View {

@Binding var items: [ClipItem]

@State private var searchText = ""

var body: some View {

VStack(spacing: 0) {

HStack {

Image(systemName: "magnifyingglass")

.foregroundStyle(.secondary)

TextField("Search clips...", text: $searchText)

.textFieldStyle(.plain)

}

.padding(10)

.background(.bar)

Divider()

List(filteredItems) { item in

ClipRow(item: item)

.onTapGesture { paste(item) }

}

.listStyle(.plain)

Divider()

HStack {

Text("\(items.count) clips")

.font(.caption)

.foregroundStyle(.secondary)

Spacer()

Button("Clear All", role: .destructive) {

items.removeAll()

}

.buttonStyle(.plain)

.font(.caption)

}

.padding(8)

.background(.bar)

}

}

}

Info.plist:

<key>LSUIElement</key>

<true/> <!-- Hides dock icon -->

Launch at Login:

try SMAppService.mainApp.register() // Enable

try SMAppService.mainApp.unregister() // Disable

Tips for Best Results

  • 💡Use MenuBarExtra with .window style for rich UI, or .menu style for simple dropdown menus
  • 💡Set LSUIElement = YES in Info.plist to hide the dock icon
  • 💡For global hotkeys, consider the HotKey Swift package or Carbon API via CGEvent
  • 💡Test with multiple displays — menu bar apps need to handle screen changes