Controlling Do Not Disturb on Mac

I have never before had such a clear idea for a piece of software I would write if I was a programmer, because apparently no one’s written this one yet. I want an easier way to control Do No Disturb on my Mac, with several preferences and maybe even scriptability. In fact, essentially I want Caffeine or Amphetamine (which control Sleep) for Do Not Disturb.

Here’s my problem: I want to be able to automatically activate Do Not Disturb when certain apps are launched (e.g. Audio Hijack, Skype, Zoom, etc.) and then have it turn off when I quit the app. Yes, I know I can manually activate DND, but then I have to remember to turn it off. The schedule in System Prefs is no good because it’s only to turn it on and off at the same time every day!

As far as I’ve been able to discover, there are no AppleScript or Automator hooks for DND. I did find an old defaults write terminal command (like several versions of macOS ago), but while it seems to indicate that it’s on, I’m still getting notifications and the UI isn’t saying DND is on.

defaults write ~/Library/Preferences/ByHost/com.apple.notificationcenterui.*.plist doNotDisturb -boolean true (where * equals the unique alphanumeric on this machine’s plist)

When I run the command and I do a defaults read, I get the response that it’s on, but it doesn’t act like it.

So does anyone have any ideas where I go from here?

2 Likes

Looks like a keyboard maestro trick

A quick search on their forum surfaced this:

You might want to dig deeper there (if KM is an option, of course)

I too had this need a while ago. I solved what I needed using a combination of adding keyboard shortcuts into System Preferences and then calling this shortcut as an action in Keyboard Maestro. I have not written it up yet but, here are some very brief steps below:

  1. Go to system preferences–>Keyboard–>Shortcuts and assign a keyboard shortcut to “Turn Do Not Disturb On/Off”
  2. Use that shortcut as a “Type Kestroke” action in Keyboard Maestro to turn DND on and off based on any one of the Keyboard Maestro triggers.

I have a teaching setup Macro that does a number of things when run. One of those things is toggle DND using the shortcut activated by the Keystroke action in Keyboard Maestro. Once you have the Keyboard Shortcut for use in Keyboard Maestro, the options open wide.

We were typing at the same time! :slight_smile:

1 Like

Indeed! :wink: (and some more characters)

1 Like

I use an Alfred workflow that I borrowed from the internet. I type “DND 60” and Do Not Disturb is on for 60 minutes. I also use it in my own workflows.

1 Like

I should have mentioned I tried that already. It works for a while, but for some reason after a time it stops. I just get the system “bonk” noise when it fires off in KM and no DND.

That’s weird. It has been rock solid for me. :confused:

I guess you could also automate this with the find an image action in Keyboard Maestro but, my guess is that is less reliable than the solution I posted earlier.

This led me to the solution. Apparently the Applescript for option-clicking on the Notification menu bar item doesn’t work in Catalina (or perhaps my Mac) so instead I did it as an option-click using an absolute position, which does the same thing. Thank you for the link.

I had tried other KM macros, but for some reason that one didn’t come up in my searching.

1 Like

Thanks, see my solution below in which I did it with an absolute position option-click on the Notification menu bar item.

1 Like

Thank you. I have used that before, but I was hoping for something automated so I didn’t have to think about it and would go on and off automatically under the particular conditions, which I think I’ve managed to find.

There is also this little app called Muzzle, it may work for you. At least the website is a lot of fun!

Interesting. The documentation isn’t clear, but it turns on Do Not Disturb automatically when certain screen sharing apps or web services are running? I see it mention Zoom, Google Meet and Slack, but not Skype. I use Skype a lot. Do you know if it works with that? It does seem elegant and useful otherwise, especially since it activates automatically and you won’t forget.