# Excluding a Live AI Notes Window from macOS Screen Sharing: NSWindow.SharingType and ScreenCaptureKit

Single-monitor presenting on a 13-inch or 14-inch MacBook exposes an annoying tension in macOS window management. If you share a **single browser window** in Zoom, Google Meet, or Microsoft Teams, your demo stalls the moment you switch to Xcode, a terminal, or a second window. If you share your **Entire Screen**, everyone on the call sees your speaker notes, pricing checklist, and live call transcript.

When building the macOS workspace for **[GPT Realtime Assistant](https://gpt-realtime-assistant.arte-soft.com/)**—a native live transcript, 58-language two-way interpreter, and offline Apple silicon voice workspace for iPhone, iPad, and Mac—we added an opt-in **`Hide app`** button in the Mac Live toolbar (off by default). Turning it on keeps your compact notes window readable to your eyes while excluding it from screen shares, screenshots, and the app's own visual context captures.

Below are the four AppKit and `ScreenCaptureKit` details required to make per-window exclusion behave predictably in production on macOS, without kernel extensions, private APIs, or surprising the user.

---

## 1. Why Exclusion Should Be Opt-In (`Visible` by Default)

Many desktop "copilot" overlays hardcode stealth behavior permanently at launch: hiding from the Dock, disappearing from `Command-Tab`, and vanishing from screenshots even when you are working solo or pairing openly with a teammate. In daily engineering and product work, an always-invisible window feels broken—you cannot take a bug screenshot of your own workspace or switch back to it with muscle memory.

Keeping **`Hide app` off by default** (`Visible to screen sharing`) preserves standard macOS window semantics 90% of the day, while giving single-screen presenters a one-click toggle (`Hidden from screen sharing`, persisted locally in `UserDefaults`) for the 10% of the day when they share their full desktop.

---

## 2. Coordinating `NSWindow.SharingType`, Window Level, and Activation Policy

Setting `window.sharingType = .none` alone solves only half the problem: macOS `WindowServer` omits the window from standard `ScreenCaptureKit` and `CGWindowList` display streams, **but** the moment the presenter clicks into Keynote, Chrome, or Figma to drive their demo, standard window ordering buries the notes window underneath the presentation!

To keep a compact briefing column visible near the top-center webcam while excluded from the shared display stream, three AppKit properties need to change together across every host window:

```swift
import AppKit

@MainActor
final class ScreenSharePrivacyController {
    static func apply(hiddenFromShare: Bool) {
        // 1. Adjust Dock / Command-Tab footprint while hidden mode is active
        NSApp.setActivationPolicy(hiddenFromShare ? .accessory : .regular)

        for window in NSApp.windows {
            // 2. Instruct macOS WindowServer to omit or include this window in captures
            window.sharingType = hiddenFromShare ? .none : .readOnly

            // 3. Float above presentation apps while hidden so clicking slides doesn't bury notes
            window.level = hiddenFromShare ? .floating : .normal

            if hiddenFromShare {
                window.collectionBehavior.insert([.canJoinAllSpaces, .fullScreenAuxiliary])
            } else {
                window.collectionBehavior.remove([.canJoinAllSpaces, .fullScreenAuxiliary])
            }
        }

        if !hiddenFromShare {
            NSApp.activate(ignoringOtherApps: true)
        }
    }
}
```

Two subtleties worth noting on recent macOS releases:
- **SwiftUI child sheets and popovers create new `NSWindow` instances dynamically.** If a user opens a settings popover or template picker *after* toggling `Hide app` on, that newly instantiated `NSWindow` defaults back to `.readOnly` unless you observe `NSWindow.didBecomeKeyNotification` / `didUpdateNotification` and re-apply `.none` while the toggle is active.
- **`.fullScreenAuxiliary` matters for Keynote and browser full-screen spaces.** Without `.fullScreenAuxiliary`, entering native macOS full-screen Space mode hides normal floating windows on another Space.

---

## 3. Preventing the "Hall of Mirrors" in `ScreenCaptureKit` Vision Captures

GPT Realtime Assistant on Mac also lets you click **Screenshot** or **Record** in the Live toolbar so the multimodal model can read an error stack trace, architecture diagram, or spreadsheet currently on your display—while capturing call audio locally via `ScreenCaptureKit` (with zero calendar bots dialing into Zoom, Meet, or Teams).

If the assistant window is floating *on top* of the target IDE or chart when you trigger a display capture, capturing the raw display without filtering feeds the vision model a screenshot of the assistant's own transcript UI—wasting visual tokens and obscuring the underlying window.

`SCContentFilter` solves this cleanly at the OS compositor layer when you exclude your own bundle's `SCRunningApplication`:

```swift
import ScreenCaptureKit

func makeSelfExcludingDisplayFilter() async throws -> SCContentFilter {
    let content = try await SCShareableContent.excludingDesktopWindows(
        false,
        onScreenWindowsOnly: true
    )
    guard let mainDisplay = content.displays.first else {
        throw CaptureError.noDisplayAvailable
    }

    let ownBundleID = Bundle.main.bundleIdentifier
    let excludedApps = content.applications.filter { app in
        app.bundleIdentifier == ownBundleID
    }

    // Composites the display underneath as if our floating window were not there
    return SCContentFilter(
        display: mainDisplay,
        excludingApplications: excludedApps,
        exceptingWindows: []
    )
}
```

Because macOS composites `SCContentFilter` on the GPU inside `WindowServer`, the captured frame contains the clean underlying code editor or slide deck—zero flickering, zero hiding-and-reshowing window hacks.

---

## 4. Pairing Screen-Share Exclusion With Zero-Cloud Apple Silicon Inference

On confidential engineering or legal reviews, visual screen-share privacy is often paired with strict network boundaries. Alongside direct client-to-OpenAI Realtime WebRTC streaming for cloud sessions, we built an explicit local inference path on Apple silicon Macs (`M1`–`M4`, macOS 26+):

| Capability | Cloud Session (Realtime API) | Offline Apple Silicon Session |
| :--- | :--- | :--- |
| **Speech Recognition** | OpenAI Realtime multimodal audio | **Whisper Large v3 Turbo** (on-device) |
| **Reasoning / Answers** | Spoken + written answers, 58-lang 2-way voice | **Qwen 3 8B** (written text answers only) |
| **Network Traffic** | Encrypted direct stream (ephemeral token) | **Zero packets** (works with Wi-Fi off) |
| **Credit Usage** | Metered from monthly / pack credits | **0 AI credits** (active plan required) |

As we documented in *[Downloaded Is Not Selected](https://dev.to/mincho_milev_c7753077d5af/downloaded-is-not-selected-managing-whisper-and-qwen-models-in-a-native-voice-app-44h3)*, keeping model download state strictly separate from active session routing ensures a local session never silently falls back to a cloud socket when Wi-Fi drops.

---

## 5. Honest Technical & Physical Boundaries

Marketing around "invisible screen-share overlays" online frequently exaggerates what user-space macOS APIs can and cannot do. Being explicit with users builds far more trust than hype:

1. **Excluded (`Yes`):** Standard display and window shares in Zoom, Google Meet (Chrome, Safari, Edge), Microsoft Teams, Slack Huddles, Webex, Discord, QuickTime / OBS macOS Screen Capture, and `Command-Shift-3` / `Command-Shift-4` screenshots.
2. **Not excluded — Acoustic audio:** `NSWindow.SharingType` is purely visual. If spoken AI replies or spoken translations play through MacBook speakers without headphones, your microphone will pick them up. Mute spoken output or wear headphones on calls.
3. **Not excluded — System cursor movement:** Viewers still see your macOS mouse pointer move across the shared desktop even when clicking inside an excluded window.
4. **Not excluded — Hardware HDMI splitters & external cameras:** Capture cards read the physical display output pipeline, and dedicated exam-proctoring software inspects running processes directly (where external tools are prohibited anyway). Always follow organizational, interview, and recording-consent rules.

We published a small standalone Swift reference repository with verification checklists and `NSWindow.SharingType` + `SCContentFilter` examples at **[github.com/minchopm/macos-screen-share-voice-notes](https://github.com/minchopm/macos-screen-share-voice-notes)**, alongside full user guides at **[gpt-realtime-assistant.arte-soft.com](https://gpt-realtime-assistant.arte-soft.com/articles/hide-app-window-during-mac-screen-sharing/)** and the **[App Store listing](https://apps.apple.com/us/app/gpt-realtime-assistant/id6770536523)**.
