Hi!
Maybe it helps someone - I was just writing a Keyboard Maestro Script to setup my Screen-recording environment. And one of the things I wanted there is a Way to Turn On Do not Disturb.
I googled a lot most approached didn’t work or I didn’t like - but with that inspiration, here is a working shell script:
Turn DND On
--- snip
defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean true
defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturbDate -date "`date -u +\"%Y-%m-%d %H:%M:%S +0000\"`"
killall NotificationCenter
dnd=$(defaults read ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb)
if [[ $dnd -eq 1 ]]; then
echo "Turned DND is ON!"
elif [[ $dnd -eq 0 ]]; then
echo "Turned DND is OFF!"
fi
--- snap
Turn DND Off
--- snip
defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean false
sleep 1
killall NotificationCenter
dndStat=$(defaults 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
--- snap
I use that as a Execute Shell Script in Keyboard Maestro.
Cheers,
Chris