Getting/Setting Do Not Disturb

(Christopher Stone) #1

Hey Folks,

Does anyone know how to get the status of Do Not Disturb via Defaults?

And how to set them?



(Christopher Stone) #2

Hey Folks,

I’ve discovered how to do this in the shell thanks to @Onan on the Keyboard Maestro Forum.

dndStat=$(defaults -currentHost read ~/Library/Preferences/ByHost/ doNotDisturb)

if [[ $dndStat -eq 1 ]]; then
   echo "DND is ON!"
elif [[ $dndStat -eq 0 ]]; then
   echo "DND is OFF!"

My attempts to read that property with AppleScriptObjC have so far failed…


(Shane Stanley) #3

Does this help?

use AppleScript version "2.7"
use framework "Foundation"
use scripting additions

set theDefaults to current application's NSUserDefaults's alloc()'s initWithSuiteName:""
theDefaults's boolForKey:"doNotDisturb"