Skip to main content
Solved

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


Cayde-6
Forum|alt.badge.img+22
  • Honored Contributor
  • 606 replies

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

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

Best answer by Cayde-6

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 original
Did this topic help you find an answer to your question?

6 replies

Forum|alt.badge.img+15
  • Valued Contributor
  • 301 replies
  • November 29, 2018

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
Forum|alt.badge.img+22
  • Author
  • Honored Contributor
  • 606 replies
  • November 29, 2018

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


mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • November 29, 2018

@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.


Forum|alt.badge.img+15
  • Valued Contributor
  • 301 replies
  • November 29, 2018

@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
Forum|alt.badge.img+22
  • Author
  • Honored Contributor
  • 606 replies
  • Answer
  • December 3, 2018

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


Forum|alt.badge.img+1
  • New Contributor
  • 1 reply
  • December 21, 2021
Cayde-6 wrote:

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 )


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings