Unobtrusive Mac Apps

How to build a Mac app that starts when something calls it, shows nothing until a decision is yours, and quits when it's done.

A painted London street at nightfall in thick blue fog. A lamplighter in a long coat and cap reaches up with his pole to a gas lamp that glows soft orange over wet cobblestones; down the street a couple walks arm in arm past a few lit windows, and a horse-drawn carriage waits in the mist.

Latchkey is now Pistachio.

A painted London street at nightfall in thick blue fog. A lamplighter in a long coat and cap reaches up with his pole to a gas lamp that glows soft orange over wet cobblestones; down the street a couple walks arm in arm past a few lit windows, and a horse-drawn carriage waits in the mist.

How to build a Mac app that stays out of the way. It starts when something calls it, shows nothing until a decision is yours, and quits when it's done. If you opened it yourself, it behaves like any other app.

It describes what Peel and Pistachio do, and marks what is proposed or not yet verified. Paths are relative to each app's repository. Pistachio's paths link to its public source; Peel's source is private.

The model: passive and user-facing sessions

Every run of the app is one of two kinds, decided when it starts:

  • Passive. Something other than you started the app to get work done: Finder opening a file, the app's command-line tool, an agent, a browser extension's helper. It has no window and no Dock icon, only an optional menu bar icon. It interrupts only for decisions that are yours, such as an approval or Touch ID, and quits once it has nothing left to do.
  • User-facing. You opened the app yourself, from Finder, the Dock, Spotlight, Launchpad or its own menu. It has a window and a Dock icon and stays until you quit it. Work that arrives from elsewhere runs alongside.

A passive session becomes user-facing the moment you open the app's window. It never goes the other way. Peel documents this rule in app/Peel/AppDelegate.swift (the type comment above AppDelegate).

1. Install

  • One bundle. Everything ships inside the .app:

    • the command-line tool, linked into ~/.local/bin only when you choose to install it;
    • extensions under Contents/PlugIns;
    • any login or launchd helper under Contents/Library/LoginItems or Contents/Library/LaunchAgents.
  • No installer, no privileged helper, nothing written outside your home folder. Dragging the app to Applications is enough.

  • Signing. The direct download is signed with Developer ID. Apple re-signs App Store and TestFlight builds with its own certificate, and that certificate doesn't name your team. Every identity check between the app's parts must accept both forms:

    • the team's own certificate: certificate leaf[subject.OU] = "TEAM";
    • or Apple's App Store leaf (field.1.2.840.113635.100.6.1.9) or TestFlight leaf (…6.1.25.1), bound to the team by the sealed com.apple.application-identifier entitlement (TEAM.bundle.id).

    Pistachio: Sources/LatchkeyCore/CodeIdentity.swift, requirement(_:team:).

  • Duplicate copies. A direct download and a TestFlight build can be installed at once, and Launch Services prefers one of them in an order you don't control. Treat it like a security protocol:

    1. List every copy with NSWorkspace.urlsForApplications(withBundleIdentifier:).
    2. Check each copy's signature, and ignore any that fail. Never read an unverified copy's Info.plist.
    3. Connect only to a verified copy, and only after authenticating the process on the other end.
    4. Start only one verified copy. If several could serve and none is running, start none and say why.
    5. When the choice is ambiguous, fail closed.

    Pistachio: clientEndpoint() in Sources/latchkey/main.swift, and BrokerEndpoint.installedKind and BrokerEndpoint.copyToStart in Sources/LatchkeyCore/BrokerEndpoint.swift.

2. Launch reasons

Record why the app started, once, as early as possible:

Reason How it's detected Session
You opened it No argument; a Finder, Dock, Spotlight or Launchpad launch User-facing
A file, URL or Service application(_:open:) and Apple events, before applicationDidFinishLaunching Passive
A request from the tool or a helper An argument the caller passes through NSWorkspace.OpenConfiguration.arguments Passive
Login SMAppService.mainApp or an agent Passive (menu bar only)
  • A caller starts the app with activates = false, hides = true and addsToRecentItems = false. The start takes no focus and leaves no Recents entry.
  • Pistachio passes --for-request (Sources/LatchkeyCore/BackgroundLaunch.swift). Peel tells its sessions apart from the open events it receives (app/Peel/AppDelegate.swift, application(_:open:) and launchedForHandoff).
  • Opening the app yourself always wins. applicationShouldHandleReopen (the Dock icon, or opening the app again) and every "Open" command make the session user-facing.

3. Windows, the Dock and panels

  • Activation policy. Start as .accessory, which has no Dock icon. Switch to .regular while a window you opened is visible, and back to .accessory when it closes. Prefer this to LSUIElement, which hides the Dock icon even when you open the app on purpose. Peel: app/Peel/AppDelegate.swift (setActivationPolicy). Pistachio: App/Latchkey/LatchkeyApp.swift (the main Window scene's onAppear and onDisappear).
  • SwiftUI scenes. A Window with .defaultLaunchBehavior(.presented) opens on every launch. A passive session has to keep it from showing. Pistachio dismisses it as soon as it appears, which isn't seen because the app was started hidden. Choosing .suppressed from the launch reason, so the window is never created, is the cleaner version (proposed).
  • Interruptions are panels, not windows. Use a non-activating floating NSPanel (.nonactivatingPanel, .floating, .canJoinAllSpaces, .fullScreenAuxiliary) that appears over whatever you're doing without taking focus.
    • Run Touch ID inside the panel with LAAuthenticationView instead of the system sheet.
    • Give every request a timeout. Pistachio's is 120 seconds: App/Latchkey/ApprovalPanel.swift, PanelApprover.
  • Results without a window. Use a UNUserNotificationCenter notification or a small heads-up display. Peel shows a compact HUD for passive extraction.

4. Menu bar

  • Use an AppKit NSStatusItem. SwiftUI's MenuBarExtra can't tell a click from a right-click.

    • Click: an NSPopover with .transient behavior. Put Open at the top, then search with keyboard focus, then quick actions (copy, end a grant), then the latest status, with Lock, Settings and Quit at the bottom.
    • Right-click or Control-click: a short NSMenu with Open, New, Lock, Settings and Quit.

    Pistachio: App/Latchkey/MenuBarPanel.swift, MenuBarItem.

  • Icon. A template image (isTemplate = true), about 18 pt, with an accessibilityDescription. Keep one asset per icon choice.

  • Always present while running. The icon is how you find a passive session, see what it's doing and quit it. Quit in the menu bar always quits for real, whatever the "keep running" setting says.

5. Icons

Surface Source Changeable at runtime
Finder, Applications, Launchpad, Spotlight The bundle's icon (Icon Composer .icon in the asset catalog) No. It means editing the signed bundle, which breaks the signature; App Store copies are read-only
Dock, while running NSApp.applicationIconImage (nil restores the bundle icon) Yes, while running
Menu bar The template asset for the chosen icon Yes
In-app tiles The app's own views Yes

A Settings choice of icon can therefore change everything except Finder and Launchpad. Pistachio: App/Latchkey/AppBranding.swift.

6. Doing work while the app isn't running

Choose the lightest mechanism that fits:

  1. The system runs it. Extensions run on their own: Quick Look previews, Spotlight importers, Finder Sync, file providers, Safari web extensions. Peel's previews, Spotlight and Finder menu work this way.
  2. The caller starts it. The command-line tool connects to the app's socket. If nothing answers, it starts the app with the request argument and waits about ten seconds for an answer. This works with App Store builds, because the tool isn't sandboxed. Pistachio: launchApp() in Sources/latchkey/main.swift.
  3. launchd starts it (proposed, not verified). A launch agent registered with SMAppService.agent(plistName:), declaring MachServices or Sockets. launchd starts the process when something first connects. It needs your approval in System Settings › Login Items. Whether App Store review accepts it for a sandboxed broker hasn't been checked.
  4. Login item. SMAppService.mainApp, for work that must be ready before anything asks: scheduled jobs, or Peel's save-back folders. Make it optional and off by default.

7. Quitting when idle, and what survives

  • Peel quits about 6.5 seconds after its last passive job (app/Peel/AppDelegate.swift, idleQuitWorkItem). It stays running while any save-back folder exists, because only a running Peel can save it (app/Peel/SaveBack.swift).
  • Pistachio quits a passive session after five minutes with no requests and nothing of it on screen (BackgroundLaunch.shouldQuit in Sources/LatchkeyCore/BackgroundLaunch.swift). The rule:
    • the session is passive;
    • no window, approval panel or open menu bar panel is visible (NSApp.windows that are visible and canBecomeKey, which excludes the status item's own window);
    • the broker's last request started or finished at least five minutes ago (Broker.lastRequestAt in Sources/LatchkeyCore/Broker.swift).
  • Only passive quits bypass "keep running". They set an explicit quitting flag before NSApp.terminate.
  • Nothing important lives only in memory. Keep grants, items and log state in the keychain or on disk. Apply pending work at the next launch, as Peel applies save-back edits.
  • Sudden termination (proposed). Call ProcessInfo.processInfo.enableSuddenTermination() while idle, so logout doesn't wait on the app, and disableSuddenTermination() while an approval or a write is in progress.

8. Updates

  • App Store and TestFlight. The system updates the app. Don't build an in-app updater.
  • Direct download, with Sparkle 2:
    • SPUStandardUpdaterController with SUEnableAutomaticChecks.
    • A passive app may run rarely, so check at launch, throttled by SUScheduledCheckInterval.
    • SUAutomaticallyUpdate downloads quietly and installs when the app quits. That pairs with quitting when idle: the next passive start is already the new version.
    • Offer a found update from the menu bar, not a window that takes focus. Sparkle's gentle reminders (SPUStandardUserDriverDelegate.supportsGentleScheduledUpdateReminders) exist for background apps.
    • Give each app its own EdDSA key. Pistachio and Peel currently share one (an open issue).
  • Two copies installed. Sparkle updates only its own bundle and leaves the store copy to the App Store.

9. First run

  • Welcome only in user-facing sessions. A passive start never shows Welcome or What's New; they wait for the next time you open the app.
  • Setup is explicit and reversible.
    • Installing the command-line tool is a choice.
    • Editing another tool's config keeps the original next to it first (Pistachio: .before-pistachio, Sources/LatchkeyCore/AgentSetup.swift).
    • Create folders with explicit permissions (0755), whatever the process's umask. A process-wide umask change elsewhere, such as around binding a socket, otherwise leaks into them (Sources/LatchkeyCore/AgentSetup.swift).

10. Uninstall

Moving the app to the Trash leaves behind login and agent registrations, App Group containers, keychain items, and the tool's link in ~/.local/bin. Proposed: a Settings action that unregisters with SMAppService, removes the link, restores the files the app edited during setup, and deletes stored items only if you confirm.

11. Release checks

  • A passive start from the tool or an extension shows no window and no Dock icon, and takes no focus.
  • A passive session quits after its idle period. Opening the app afterwards works and stays open.
  • With login enabled, only the menu bar icon appears at login.
  • With two copies installed (direct and TestFlight), the verified one is used, and an ambiguous setup stops with a message.
  • Every icon choice is checked in the Dock, the menu bar, and light and dark appearance.
  • A found update is offered without opening a window, and installs at quit.

Cite as Shallbetter, Zachary. “Unobtrusive Mac Apps.” zachshallbetter.com, December 2, 2026. https://zachshallbetter.com/writing/unobtrusive-mac-apps.

Export BibTeX RIS Markdown