Skip to content

Instantly share code, notes, and snippets.

@talkingmoose
Last active February 5, 2020 15:29
Show Gist options
  • Save talkingmoose/20848f9b06a684c8d0a4b12ec67ee623 to your computer and use it in GitHub Desktop.
Save talkingmoose/20848f9b06a684c8d0a4b12ec67ee623 to your computer and use it in GitHub Desktop.
Under Apple menu > System Preferences > Notifications > Do Not Disturb: Enables Do Not Disturb and sets time range from 7:01 a.m. to 7:00 a.m., effectively disabling macOS Notifications.
#!/bin/bash
# get currently logged in user
currentUser=$( /usr/bin/stat -f "%Su" /dev/console )
echo "Current user is $currentUser."
# set Do No Disturb for the current user to enabled between 7:01 a.m. and 7:00 a.m.
su "$currentUser" -c "defaults write ~/Library/Preferences/ByHost/com.apple.notificationcenterui.plist dndEnd -int 420" # minutes
su "$currentUser" -c "defaults write ~/Library/Preferences/ByHost/com.apple.notificationcenterui.plist dndStart -int 421" # minutes
exit 0
@talkingmoose
Copy link
Author

image

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