Getting/Setting Do Not Disturb

Hey Folks,

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

And how to set them?

TIA.

-Chris

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/com.apple.notificationcenterui doNotDisturb)

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

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

-Chris

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:"com.apple.notificationcenterui"
theDefaults's boolForKey:"doNotDisturb"
2 Likes