// holder.swift: turns macOS Secure Input on for N seconds (default 6), then off.
// Posts no keys and reads nothing. To see which app macOS names while it holds:
//   swiftc holder.swift -o holder
//   ./holder 6 & sleep 2; ioreg -l -d 1 -w 0 | grep -o '"kCGSSessionSecureInputPID"=[0-9]*'; echo "holder was $!"
// From useyappr.com/blog/dictation-hotkey-not-working-mac
import Carbon
import Foundation
let secs = Double(CommandLine.arguments.dropFirst().first ?? "6") ?? 6
let st = EnableSecureEventInput()
print("holder pid=\(getpid()) enable=\(st) isEnabled=\(IsSecureEventInputEnabled())"); fflush(stdout)
Thread.sleep(forTimeInterval: secs)
DisableSecureEventInput()
print("released isEnabled=\(IsSecureEventInputEnabled())"); fflush(stdout)
