1. Home
  2. Mac OS X
  3. Schedule do not disturb in os x mountain lion with automator

Schedule ‘Do Not Disturb’ In OS X Mountain Lion With Automator

“Do Not Disturb” is a feature in Mountain Lion borrowed from iOS 6 to mute notifications from Notification Center. Unlike iOS, OS X does not allow you to schedule when the feature will be enabled or disabled. It needs to be toggled manually when required. It is programmed to enable itself at midnight each day, and there is no way to stop it from doing so. Though if you are interested in scheduling the Do Not Disturb feature by date and time of your choice, you can do so with the help of a simple AppleScript and Calendar. You will need to create Automator workflows for enabling and disabling Notification Center. The process is detailed below.

Launch Automator and select ‘Calendar Alarm’ as the type of workflow to create. Select ‘Run AppleScript’ from the actions listed in the left column, and drag & drop it on to the work area.

calendar alarm

Replace the default script with the following:

do shell script "defaults write ~/Library/Preferences/ByHost/com.apple.notificationcenterui.*.plist doNotDisturb -boolean true"
set theDate to quoted form of (do shell script "date +\"%Y-%m-%d %I:%M:%S +0000\"")
do shell script "defaults write ~/Library/Preferences/ByHost/com.apple.notificationcenterui.*.plist doNotDisturbDate -date " & theDate
do shell script "killall NotificationCenter"

Save the Calendar alarm that you’ve just created. Doing so will create an Automator calendar in the Calendar app, and you will see the alarm you saved appear in it as an event. It will have the same name that you saved the alert with. Edit the date  & time for this event to whenever you want to turn Do not Disturb on. If you are interested in knowing how it works, the alert is set to open a file, and the file that opens is automatically set to the calendar alert you created.

Screen Shot 2013-02-06 at 12.35

When the event is active and the script executes, Notification Center will quit itself and launch again to put the changes in effect. If you leave it like this, Do Not Disturb will be enabled until midnight when Mountain Lion disables it automatically. If you would like to disable it and enable it for a specific period in a day, you will need to create a Calendar alarm that disables Do Not Disturb. To create the alert, follow the same procedure as above, but use the following script instead:

do shell script "defaults write ~/Library/Preferences/ByHost/com.apple.notificationcenterui.*.plist doNotDisturb -boolean false"
try
do shell script "defaults delete ~/Library/Preferences/ByHost/com.apple.notificationcenterui.*.plist doNotDisturbDate"
end try
do shell script "killall NotificationCenter"

This Calendar alarm – like the previous one – will create an event in the Automator calendar. Just set it for whenever you want Do Not Disturb to be disabled and for Notification Center to start giving you alerts.

These scripts work perfectly but there is one small caveat: if you plan to keep Do Not Disturb on all night, you will have to add the event twice because Mountain Lion disables it at midnight everyday. Other than that, this is a simple way to schedule Do Not Disturb.

[via TUAW]