Using Objective-C, how can I programmatically check the state of the system \"Do Not Disturb\" setting on OS X? I\'m fine with using hacks or private APIs since I don\'t need to
You can (and should) simply use UserDefaults:
let theDefaults = UserDefaults(suiteName: "com.apple.notificationcenterui")
print(theDefaults?.bool(forKey: "doNotDisturb"))
For time-controlled switching you should check if the minute of the day lies between dndStart and dndEnd:
let theDefaults = UserDefaults(suiteName: "com.apple.notificationcenterui")
let theDate = Date()
let theCalendar = Calendar.current
let theHour = calendar.component(.hour, from: theDate)
let theMinute = calendar.component(.minute, from: theDate)
let theMinuteOfDay = Double(theHour * 60 + theMinute)
if theMinuteOfDay >= theDefaults.double(forKey: "dndStart") &&
theMinuteOfDay <= theDefaults.double(forKey: "dndEnd") {
// ...
}