I'd like to have Do Not Disturb enabled when I'm using either of two apps that I use for presenting to clients because I don't want a text message to pop up during a meeting.
I've set a keyboard shortcut to toggle DND in the Mac system preferences but I'm struggling to figure out the series of triggers and conditions that will turn it on when I launch one of the apps and turn it off when quit the app. I need to make sure that it doesn't turn off until both apps are quit.
Here is a macro that will do what you want automatically. When specific applications are launched, Do Not Disturb is enabled. When any of the specific applications are quit, it will only disable Do Not Disturb if all of the applications are not running.
In this macro, I have configured Safari and App Store as the applications. Obviously you would change these to the apps you wish, but just make sure to change both locations. There is a comment in the macro explaining it in more details.
Thank you very much. I've adjusted the macro to reflect my apps but it seems that there is something broken. When I open one of the apps, the Notification Center opens but DND does not get turned on... Do you know if this works with Mojave?
@Tom's Post #9 is the simplest solution to this puzzle.
But – it's handy to be able to check the status of Do Not Disturb.
-Chris
--------------------------------------------------------
# Auth: Christopher Stone <scriptmeister@thestoneforge.com>
# dCre: 2021/09/10 08:21
# dMod: 2021/09/10 08:21
# Appl: Miscellaneous AppleScript
# Task: Get the Status of Do Not Disturb
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @DND, @Do_Not_Disturb, @Status
# Test: macOS 10.14.6
# Vers: 1.00
--------------------------------------------------------
set dndStatus to getDND_Status()
--------------------------------------------------------
--» HANDLERS
--------------------------------------------------------
on getDND_Status()
set shCmd to "defaults -currentHost read com.apple.notificationcenterui doNotDisturb"
set dndStatus to ((do shell script shCmd) as number) as boolean
return dndStatus
end getDND_Status
--------------------------------------------------------
Hey Chris, I'm getting the following error with this macro (I had to change the AppleScript settings to disable failure aborts as well as to include errors)
What happens when you run this in Script Debugger?
set checkDNDstatusCMD to ¬
{"defaults -currentHost read", space, ¬
"~/Library/Preferences/ByHost/", ¬
"com.apple.notificationcenterui", ¬
space, "doNotDisturb"} as text
set statusOfDND to (do shell script checkDNDstatusCMD) as number as boolean
2021-09-10 11:46:11.899 defaults[34156:327801]
The domain/default pair of (/Users/cdthomer/Library/Preferences/ByHost/com.apple.notificationcenterui, doNotDisturb) does not exist
#!/bin/bash
set -eou pipefail
# From https://heyfocus.com/enabling-do-not-disturb-mode and
# https://apple.stackexchange.com/questions/145487
if [[ $(defaults -currentHost read ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb) -eq 0 ]]; then
defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean true
defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturbDate -date "`date -u +\"%Y-%m-%d %H:%M:%S +000\"`"
killall NotificationCenter
echo "Do Not Disturb is enabled. Run $0 to turn it off (OS X will turn it off automatically tomorrow)."
else
defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean false
killall NotificationCenter
echo "Do Not Disturb is disabled. Run $0 to turn it on again."
fi