MicGuard

Prevents Bluetooth audio devices from hijacking the default macOS microphone

View the Project on GitHub pszypowicz/MicGuard

Distributed Notifications

MicGuard posts macOS distributed notifications that any app or script can observe to react to mic state changes.

Home · CLI Reference · Debugging · Integrations · Releasing

Notification reference

Notification Direction Posted when
com.pszypowicz.MicGuard.statusChanged Outbound Device change, enabled toggle, app launch, ping response
com.pszypowicz.MicGuard.appTerminated Outbound The app is about to quit
com.pszypowicz.MicGuard.requestStatus Inbound External consumers post this to request a status re-broadcast
com.pszypowicz.MicGuard.toggleMute Inbound Toggle mute on the current input device
com.pszypowicz.MicGuard.setVolume Inbound Set input volume (expects userInfo["volume"] as string 0-100)

Payload schema

statusChanged userInfo

Key Type Values
enabled String "1" (enabled) or "0" (disabled)
device String Current input device name (e.g. "MacBook Pro Microphone")
volume String Input volume "0""100"
muted String "1" (muted) or "0" (not muted)

Volume and mute changes are debounced (100ms) before posting statusChanged.

setVolume userInfo

Key Type Values
volume String Desired volume "0""100"

Other notifications carry no userInfo payload.

API stability

MicGuard is pre-1.0. Notification names and payload schema may change before version 1.0.0.

Observing notifications

Swift

import Foundation

let center = DistributedNotificationCenter.default()

center.addObserver(
    forName: NSNotification.Name("com.pszypowicz.MicGuard.statusChanged"),
    object: nil,
    queue: .main
) { notification in
    let info = notification.userInfo as? [String: String] ?? [:]
    let enabled = info["enabled"] == "1"
    let device = info["device"] ?? ""
    let volume = info["volume"] ?? "0"
    let muted = info["muted"] == "1"
    print("MicGuard: enabled=\(enabled) device=\(device) volume=\(volume) muted=\(muted)")
}

Shell (SketchyBar)

SketchyBar can subscribe to distributed notifications as custom events:

# Register the distributed notification as a SketchyBar event
sketchybar --add event mic_status_changed "com.pszypowicz.MicGuard.statusChanged"

# Subscribe an item to the event
sketchybar --subscribe mic mic_status_changed

Shell (generic)

You can observe notifications from the command line using notificationlistener or similar tools, but the most practical approach is through an app that supports distributed notification subscriptions (like SketchyBar, Hammerspoon, or a custom Swift script).

Use cases