Skip to content

Instantly share code, notes, and snippets.

@ryangreenberg
Created October 24, 2017 22:40
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryangreenberg/5267f68a8e7b07ea66370b4eb5580ab9 to your computer and use it in GitHub Desktop.
Save ryangreenberg/5267f68a8e7b07ea66370b4eb5580ab9 to your computer and use it in GitHub Desktop.
Do Not Disturb
#!/bin/bash
set -eou pipefail
# From https://heyfocus.com/enabling-do-not-disturb-mode and
# https://apple.stackexchange.com/questions/145487
if [[ $(defaults -currentHost read ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb) -eq 0 ]]; then
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 +000\"`"
killall NotificationCenter
echo "Do Not Disturb is enabled. Run $0 to turn it off (OS X will turn it off automatically tomorrow)."
else
defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean false
killall NotificationCenter
echo "Do Not Disturb is disabled. Run $0 to turn it on again."
fi
@dylan-chong
Copy link

Dnd doesnt appear to be changed on high sierra/mojave with this solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment