Problem
I’m not a fan of the “Do Not Disturb” feature implementation on Mac for two reasons:
- It does not disable app badges (the red tags on icons in the dock)
- It does disable notification banners, but it’s a hammer in that it’ll disable all of them, including calendar notifications that you might still want to see while chat and slack stay off.
I created an apple script to help me solve those two issues and achieve a “one-button” toggle between a focus mode when I want to be completely distraction-free, yet aware of the calendar or other critical notifications while disabling notifications and badging on chat and messenger type apps.
Solution
First, setup Script Editor for a quick easy toggle of the script by opening “Script Editor” on Mac. Then from the menu bar go to Script Editor > Preferences and toggle the “Show Script menu in menu bar”
Then click on the Script Editor menu bar icon, which should look like so , and go to Open Scripts Folder > Open User Scripts Folder
In that directory, place the script i provide below and give it a name you like e.g “Focus Mode” or “No Notifications”. Note that you have some choices of how to execute this script. Since notification settlings are a toggle and not a state definition — at least as far as i can control with AppleScript, the same code that turns them off is the same that turns them back on again. So, i named mine “Notifs Trigger” and for some kind of psychological confirmation, the script triggers a notification at the end of each run stating that the state has changed.
It does take a few seconds to run, but while it’s running you’ll see a gear icon in the menu bar indicating that.
The script is below, copy and paste it into the mac Script Editor. You can customize it for your use case, most likely you have a different set of apps or a different number. For different apps, edit the appName variable at the top*. If you have fewer or more apps, remove or add the extra blocks. I’ve inserted a line break between each block to make it easy to identify.
P.S you can find the exact app name by opening the Activity Monitor and finding the relevant process, it should be mostly straightforward, i.e Whats App is “WhatsApp”
Code is also available on GitHub
set appName to "Discord"
set appName2 to "Messages"
set appName3 to "Messenger"
set appName4 to "WhatsApp"
if running of application "System Preferences" then
quit application "System Preferences"
delay 1
end if
tell application "System Preferences"
set the current pane to pane id "com.apple.preference.notifications"
delay 1
tell application "System Events"
tell table 1 of scroll area 1 of window 1 of application process "System Preferences"
repeat with i from 2 to (count rows)
if value of static text 1 of group 1 of UI element 1 of row i is appName then
select row i
exit repeat
end if
end repeat
end tell
delay 0.2
click button 0 of group 0 of window 1 of application process "System Preferences"
tell table 1 of scroll area 1 of window 1 of application process "System Preferences"
repeat with i from 2 to (count rows)
if value of static text 1 of group 1 of UI element 1 of row i is appName2 then
select row i
exit repeat
end if
end repeat
end tell
delay 0.2
click button 0 of group 0 of window 1 of application process "System Preferences"
tell table 1 of scroll area 1 of window 1 of application process "System Preferences"
repeat with i from 2 to (count rows)
if value of static text 1 of group 1 of UI element 1 of row i is appName3 then
select row i
exit repeat
end if
end repeat
end tell
delay 0.2
click button 0 of group 0 of window 1 of application process "System Preferences"
tell table 1 of scroll area 1 of window 1 of application process "System Preferences"
repeat with i from 2 to (count rows)
if value of static text 1 of group 1 of UI element 1 of row i is appName4 then
select row i
exit repeat
end if
end repeat
end tell
delay 0.2
click button 0 of group 0 of window 1 of application process "System Preferences"
end tell
quit
display notification "notification settings changed"
end tell