Do Not Disturb - Turn on When Display Sleeping setting via Terminal?

Cayde-6
Release Candidate Programs Tester

Has anyone managed to apply the following setting from the terminal?

System Prefs > Notifications > Do Not Disturb > Check When the display is sleeping

1 ACCEPTED SOLUTION

Cayde-6
Release Candidate Programs Tester

So it actually turns out trying to modify the UUID.plist file directly caused problems. The below is how I've now managed to fix the issue

Get the current logged in username (jamf recommended method)

loggedInUser=$(python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + " ");')

Enables Do Not Disturb during Display Sleep

sudo -u ${loggedInUser} defaults -currentHost write com.apple.notificationcenterui dndEnabledDisplaySleep -bool YES

View solution in original post

6 REPLIES 6

sshort
Valued Contributor

You might have to tinker with a scalable/scriptiable solution b/c there seems to be a unique ID appended to the plist that preference is stored in. You can check against what you see on your machine...

sudo defaults write ~/Library/Preferences/ByHost/com.apple.notificationcenterui.0954B6FD-C914-51EF-8955-90DA3DC3AFCE.plist dndEnabledDisplaySleep -bool YES

Cayde-6
Release Candidate Programs Tester

@sshort Out of Interest, did you already know that or how did you come upon that PLIST?

mm2270
Legendary Contributor III

@LewisB Any plists stored in the ByHost folder in ~/Library/Preferences/ have the Mac's UUID number appended to them, which is what that long string of numbers/letters is.

You can find your Mac's UUID by doing ioreg -rd1 -c IOPlatformExpertDevice | awk -F" '/IOPlatformUUID/{print $4}' What that outputs should match with a plist in that folder as part of the name like shown above.

sshort
Valued Contributor

@LewisB at my $previousjob I had an exec that couldn't enable that feature for some reason (was greyed out). So I had to track down that plist and enable using that defaults command in Terminal

@mm2270 awesome! that's super helpful

Cayde-6
Release Candidate Programs Tester

So it actually turns out trying to modify the UUID.plist file directly caused problems. The below is how I've now managed to fix the issue

Get the current logged in username (jamf recommended method)

loggedInUser=$(python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + " ");')

Enables Do Not Disturb during Display Sleep

sudo -u ${loggedInUser} defaults -currentHost write com.apple.notificationcenterui dndEnabledDisplaySleep -bool YES

Just a note for folks referred here by Box’ support article on File Provider Extensions: the invocation of Python in the example here will trigger user notifications unless the system has been configured to use an installed version of Python 3, as Apple is deprecating Python version 2 and will stop including it with macOS at some future point. You can avoid this by obtaining the logged-in user’s name this way:

loggedInUser=$( stat -f %Su /dev/console )