Skip to content

Instantly share code, notes, and snippets.

@mareksuscak
Last active January 25, 2018 16:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mareksuscak/0762545df0f6640ab81dca620cbe18a6 to your computer and use it in GitHub Desktop.
Save mareksuscak/0762545df0f6640ab81dca620cbe18a6 to your computer and use it in GitHub Desktop.
How to Activate MacOS's "Do not Disturb" — shamelessly copied from https://github.com/johnotander/do-not-disturb
# Disable DND on non-Sierra
osascript >/dev/null <<'END'
tell application "System Events"
tell application process "SystemUIServer"
try
if exists menu bar item "Notification Center, Do Not Disturb enabled" of menu bar 2 of application process "SystemUIServer" of application "System Events" then
key down option
click menu bar item "Notification Center, Do Not Disturb enabled" of menu bar 2
key up option
end if
on error
key up option
end try
end tell
end tell
END
# Disable DND on Sierra and above
osascript >/dev/null <<'END'
tell application "System Events"
tell application process "SystemUIServer"
try
if exists menu bar item "Notification Center, Do Not Disturb enabled" of menu bar 1 of application process "SystemUIServer" of application "System Events" then
key down option
click menu bar item "Notification Center, Do Not Disturb enabled" of menu bar 1
key up option
end if
on error
key up option
end try
end tell
end tell
END
# Enable DND on non-Sierra
osascript >/dev/null <<'END'
tell application "System Events"
tell application process "SystemUIServer"
try
if not (exists menu bar item "Notification Center, Do Not Disturb enabled" of menu bar 2 of application process "SystemUIServer" of application "System Events") then
key down option
click menu bar item "Notification Center" of menu bar 2
key up option
end if
on error
key up option
end try
end tell
end tell
END
# Enable DND on Sierra and above
osascript >/dev/null <<'END'
tell application "System Events"
tell application process "SystemUIServer"
try
if not (exists menu bar item "Notification Center, Do Not Disturb enabled" of menu bar 1 of application process "SystemUIServer" of application "System Events") then
key down option
click menu bar item "Notification Center" of menu bar 1
key up option
end if
on error
key up option
end try
end tell
end tell
END
@mareksuscak
Copy link
Author

You can integrate this script with the Focus app.

@mtomas
Copy link

mtomas commented Jan 25, 2018

fucking awesome ! thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment