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