Schedule Do Not Disturb On Your Mac To Stay Focused [OS X Tips]

By

Do Not Disturb

I love Do Not Disturb on my iPhone. I’ve got it scheduled to activate at 8 pm each night, and de-activate at 7 am every morning. That way, all except the most important things get to bother me when I’m with my family, in bed, and sleeping.

Mac OS X has a Do Not Disturb feature, as well, but it has to be manually activated at the top of the Notification Center by toggling the Show Alerts and Banners button to OFF. Wouldn’t it be cool if you could schedule it to turn off and on at specific times? The Automator script for Calendar below will do just that.

First up, launch Automator and select Calendar Alarm from the list of workflow types. Select Run AppleScript from the left column, and then drag and drop the Calendar Alarm to the work area.

Delete the default AppleScript that shows up once you drag and drop to 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"

Now, save the Calendar alarm you created, naming it something clever, like “Do Not Disturb,” launch Calendar, and you’ll see an “Automator” calendar in your Calendar app. You’ll also see the alarm you created above in this calendar as an event, named the same thing you chose when you saved the Automator script. Double click on the event to edit it. Set the event to an every day repeating event, with the time you’d like the Do Not Disturb to begin.

Now, Mountain Lion re-enables Notification Center every day at midnight. I have no idea why; it just does. If you want to disable it overnight, you’ll need to create a second event to activate at 12:01 am.

So, you’ve got your Do Not Disturb feature turned on. Now we need to create another script to turn it off, thereby letting the notifications through as per usual. Create a second Calendar Alarm in Automator, select Run AppleScript, and put the following in there:

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"

Save this script as something like “Enable Notifications” and then open Calendar again, editing the event for a daily repeating schedule at the time you want your notifications to come through. Now you’re done!

Source: TUAW
Via: Addictive Tips

Newsletters

Daily round-ups or a weekly refresher, straight from Cult of Mac to your inbox.

  • The Weekender

    The week's best Apple news, reviews and how-tos from Cult of Mac, every Saturday morning. Our readers say: "Thank you guys for always posting cool stuff" -- Vaughn Nevins. "Very informative" -- Kenly Xavier.