Prevents Bluetooth audio devices from hijacking the default macOS microphone
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 | 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) |
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.
MicGuard is pre-1.0. Notification names and payload schema may change before version 1.0.0.
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)")
}
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
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).