Toggling 'Do not disturb' (OS X 10.10 Notifications)

There's probably a better way, but this seems to be working on Yosemite:

tell application id "sevs"
	tell application process "SystemUIServer"
		key down option
		click (first menu bar item of menu bar 2 where name begins with "Notif")
		key up option
	end tell
end tell
1 Like

PS for KM actions which either definitely ALLOW or definitely PREVENT disturbance by notifications (rather than simply toggling), you could, of course, use something like this:

tell application id "sevs"
	tell application process "SystemUIServer"
		set mnu to first menu bar item of menu bar 2 where name begins with "Notif"
		set blnDisturbing to (name of mnu) does not end with "enabled"
		if pDisturb is not blnDisturbing then
			key down option
			click mnu
			key up option
		end if
	end tell
end tell
1 Like

You can set a shortcut directly in System Preferences for this one, too.

2 Likes

Thanks – good point – and of course you can option-click the top right notification icon too

( I’m using a KM action because its part of a general set of ‘suspend distraction’ manoeuvres, and its useful to run them as a batch )

1 Like

Hi guys,

This is super helpful, thank you.

I am using the keystroke tip for my automation, but what happens it that if DND is already activated, then it will be deactivated through the keystroke.

What would be the action to tell KM -if DND is already on, then do not hit the keystroke to activate DND-

This is what I tried, but it keeps on hitting the keystroke it independently of its status.

I am on "Keyboard Maestro 9.0.5 on macOS 10.15.5" and I think the Apple Script string **first** *menu bar item* **of** *menu bar* 2 **where** name **begins with** "Notif" fails.

Thanks!

That script is just:

defaults -currentHost read com.apple.notificationcenterui doNotDisturb

I'm having some issues with that simulated keystroke recently though (10.14.6)...
If I press the shortcut myself, it works. But from KM it's not working. I've tried toggling the shortcut on/off in system prefs, and tried restarting KM. It just gives me the normal error sound when I try it (including just trying that one action). :man_shrugging:t3: