Macos menubar tuist app

From TerminalSkills/skills · View interactive version

Macos menubar tuist app is an AI agent skill from the GitHub repository TerminalSkills/skills. Creates and maintains a macOS menu bar app whose Xcode project is generated by Tuist: a SwiftUI MenuBarExtra scene, no Dock icon, manifests in Swift, and a terminal loop that rebuilds and relaunches the app. Covers choosing between a menu and a panel, where fetching and state belong, Quit and Settin

How to use this skill

Skill file

macOS Menu Bar App with Tuist

Overview

A menu bar app lives as an icon next to the clock and has no Dock icon and no main window. On macOS 13 and later it takes two ingredients: a SwiftUI MenuBarExtra scene, and the Info.plist key LSUIElement set to true, which marks the bundle as an agent app. Tuist supplies the project: the targets are declared in Project.swift, tuist generate writes the .xcodeproj and .xcworkspace, and the generated files are never edited or committed. This skill covers the decisions, the manifest, the app skeleton, and a build-and-relaunch loop an agent can run without opening Xcode.

Instructions

1. Gather what you need

Ask the user:

Look up in the folder: an existing Tuist.swift, Project.swift or Workspace.swift; a pinned version in mise.toml; tuist version; xcodebuild -version; any scripts that already build or launch the app. If manifests exist, extend them; do not scaffold a second project beside them.

2. Install and pin Tuist

mise use tuist@4.210.0        # writes the version to mise.toml for everyone on the project
# or, on a single Mac:
brew tap tuist/tuist
brew install --formula tuist

tuist version

Producing a project requires a Mac that has Xcode. On Linux the only installer is mise, and anything that calls Xcode (tuist generate included) will not run.

3. Make the design decisions

| Decision | Options | How to choose |

|----------|---------|---------------|

| Presentation | .menuBarExtraStyle(.menu) (the default pull-down menu) or .window (a popover-like panel) | A menu when the content is a short list of commands and toggles. A panel when it needs custom layout, scrolling lists, text fields or charts |

| State model | @Observable class (macOS 14) or ObservableObject (macOS 13) | Follow the deployment target |

| Sources in the manifest | buildableFolders or sources globs | Buildable folders (Tuist 4.62, Xcode 16) track the file system, so adding a file needs no regeneration. With globs, run tuist generate after adding or removing files |

| Below macOS 13 | AppKit NSStatusItem | MenuBarExtra does not exist there |

| Dependencies | Tuist/Package.swift plus .external(name:) | Run tuist install before generating whenever that file changes |

Keep three layers apart, whatever the app does: a client that talks to the outside world and decodes, a store that owns state, refresh timing and errors, and views that only render the store and send it user intent. A view body that fires a request is refetched on every redraw and cannot be tested.

4. Lay out the project

Beacon/
├── Tuist.swift               # tells Tuist where the root is
├── Project.swift             # targets, Info.plist keys, deployment target
├── mise.toml                 # pinned Tuist version
├── Beacon/Sources/           # BeaconApp.swift, BuildClient.swift, BuildStore.swift, BuildListView.swift
├── BeaconTests/              # store and decoding tests
├── Scripts/dev.sh            # rebuild and relaunch
└── .gitignore                # *.xcodeproj  *.xcworkspace  Derived/  .build/

5. Write the manifests

Tuist.swift needs one line of content: let tuist = Tuist(project: .tuist()). In Project.swift, the menu bar behaviour comes from a single Info.plist entry; everything else is an ordinary macOS app target. Manifests are edited as text, or with tuist edit, which opens a temporary Xcode project with autocompletion for them.

6. Write the app

7. Build and relaunch from the terminal

#!/usr/bin/env bash
# Scripts/dev.sh — regenerate, build, restart Beacon
set -euo pipefail
cd "$(dirname "$0")/.."

APP=Beacon
PRODUCTS="$PWD/.build/DerivedData/Build/Products/Debug"

tuist generate --no-open
tuist xcodebuild build \
  -workspace "$APP.xcworkspace" -scheme "$APP" -configuration Debug \
  -destination 'platform=macOS' -derivedDataPath "$PWD/.build/DerivedData" -quiet

for pid in $(pgrep -x "$APP" || true); do kill "$pid"; done    # stop any copy that is running
"$PRODUCTS/$APP.app/Contents/MacOS/$APP" > .build/$APP.log 2>&1 &
echo "started $APP, pid $!, output in .build/$APP.log"

The script starts the executable inside the bundle directly, so the app inherits the shell's environment and its output goes to a log file; open Beacon.app would do neither. tuist generate opens Xcode unless --no-open is passed. tuist xcodebuild build is a pass-through to xcodebuild (same flags) that also reports timings to a Tuist server if one is configured; tuist build is deprecated in its favour. tuist run Beacon builds and runs a scheme in one step, but it does not stop a copy that is already running, which is why the script exists.

8. Verify before reporting

| Check | Command | Expected |

|-------|---------|----------|

| Manifests compile | tuist generate --no-open | Exit status 0, workspace written |

| App builds | Scripts/dev.sh | No errors; the script prints the new PID |

| Agent app | plutil -p .build/DerivedData/Build/Products/Debug/Beacon.app/Contents/Info.plist \| grep LSUIElement | "LSUIElement" => 1 (or true) |

| Running | pgrep -x Beacon | One PID |

| Tests | tuist test | All pass |

| Scripts | bash -n Scripts/dev.sh | No output |

Then tell the user which commands ran and what they printed, and ask them to confirm the icon is visible: an agent cannot see the menu bar, and on a crowded menu bar macOS may not show every icon.

Examples

Example 1: a new menu bar app that shows failing nightly builds

Request: "Create a menu bar app called Beacon for macOS 14 that lists our failing nightly builds. Tuist project, no Dock icon."

// Project.swift
import ProjectDescription

let project = Project(
    name: "Beacon",
    targets: [
        .target(
            name: "Beacon",
            destinations: .macOS,
            product: .app,
            bundleId: "io.harborlane.Beacon",
            deploymentTargets: .macOS("14.0"),
            infoPlist: .extendingDefault(with: [
                "LSUIElement": true,
            ]),
            buildableFolders: ["Beacon/Sources"],
            dependencies: []
        ),
        .target(
            name: "BeaconTests",
            destinations: .macOS,
            product: .unitTests,
            bundleId: "io.harborlane.BeaconTests",
            deploymentTargets: .macOS("14.0"),
            buildableFolders: ["BeaconTests"],
            dependencies: [.target(name: "Beacon")]
        ),
    ]
)
// Beacon/Sources/BuildStore.swift
import Observation

@MainActor @Observable
final class BuildStore {
    private(set) var builds: [Build] = []
    private(set) var lastError: String?
    var failing: [Build] { builds.filter { $0.status == .failed } }

    private let client: BuildClient
    init(client: BuildClient) { self.client = client }

    func refresh() async {
        do {
            builds = try await client.latestBuilds()
            lastError = nil
        } catch {
            lastError = error.localizedDescription   // keep the old list on screen
        }
    }
}
// Beacon/Sources/BeaconApp.swift
import SwiftUI

@main
struct BeaconApp: App {
    @State private var store = BuildStore(client: BuildClient())

    var body: some Scene {
        MenuBarExtra("Beacon", systemImage: store.failing.isEmpty ? "checkmark.circle" : "exclamationmark.triangle.fill") {
            BuildListView(store: store)
                .task { await store.refresh() }
        }
        .menuBarExtraStyle(.window)
    }
}

BuildClient reads its token with ProcessInfo.processInfo.environment["BEACON_CI_TOKEN"] and decodes with optional fields for anything the API may omit. BuildListView shows store.failing, the error line when lastError is set, a Refresh button and a Quit button.

tuist generate --no-open && Scripts/dev.sh

Result: Beacon.xcodeproj and Beacon.xcworkspace appear beside Project.swift, the synthesized Info.plist lands under Derived/, and the build ends without errors. pgrep -x Beacon prints one PID, nothing is added to the Dock, and the checkmark icon switches to the warning triangle when a build fails.

Example 2: adding Quit and "Launch at login" to an existing app

Request: "Beacon has no way to quit, and I want it to start when I log in."

The manifest does not change. A small section goes at the bottom of the panel:

// Beacon/Sources/PanelControls.swift
import ServiceManagement
import SwiftUI

struct PanelControls: View {
    @State private var startsAtLogin = SMAppService.mainApp.status == .enabled

    var body: some View {
        Toggle("Launch at login", isOn: $startsAtLogin)
            .onChange(of: startsAtLogin) { _, enabled in
                do {
                    if enabled { try SMAppService.mainApp.register() }
                    else { try SMAppService.mainApp.unregister() }
                } catch {
                    startsAtLogin = SMAppService.mainApp.status == .enabled   // show the real state
                }
            }
        Divider()
        Button("Quit Beacon") { NSApplication.shared.terminate(nil) }
            .keyboardShortcut("q")
    }
}

Result: because the target uses a buildable folder, the new file is picked up without regenerating; Scripts/dev.sh rebuilds and restarts the app. Turning the toggle on makes Beacon appear under System Settings, General, Login Items. If the user removes it there, the toggle shows off the next time the panel opens, because it reads status instead of a stored preference.

Guidelines

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.