AppleScripting Notification Center > Scheduling Do Not Disturb
Mountain Lion's Notification Center is great for keeping you in the loop, but it can be a huge distraction when you need to get stuff done. Sometimes, a little peace and quiet is all you need to stay productive.
As you may know, iOS 6 includes a handy Do Not Disturb feature, which can be turned on to disable notifications. It can even be set to automatically enable/disable itself at scheduled intervals. Mountain Lion also lets you disable Notification Center. Just open Notification Center and drag down to access a Show Alerts and Banners toggle switch. Note that this is a temporary setting, and disabled notifications automatically re-enable at midnight.
Unlike iOS 6, though, Mountain Lion doesn't give you an option for enabling/disabling notifications on a schedule. At least, it doesn't provide a built-in option for this. With a little customized help from AppleScript, Automator, and the Calendar app, it is possible.
In this post, you'll create two Calendar Alarm Automator workflows, which can be configured to run at scheduled times to enable or disable Notification Center alerts and banners.
Note: If you have any trouble following along, you can download the completed AppleScripts and Automator workflows here.
Building a Workflow to Enable Do Not Disturb (i.e. Disable Notification Center Alerts and Banners)
1. Launch Automator (in your /Applications folder) and create a new Calendar Alarm workflow.
2. Search the action library for the Run AppleScript action and drag it to the workflow area.
3. Replace the pre-filled AppleScript code in the Run AppleScript action with the following:
The script writes to Notification Center's property list file and enables Do Not Disturb mode. It then quits and relaunches Notification Center in order for the change to go into effect.
4. You're finished building the workflow, so go ahead and save it as Enable Do Not Disturb.
5. When you save the workflow, Automator puts it where it needs to go (the ~/Library/Workflows/Applications/Calendar folder). The Calendar app launches and a new event is created in an Automator calendar, which Automator creates if it doesn't already exist. The event should be configured with an Open File alarm that's set to run the workflow. Schedule the event for the desired time, such as every weekday morning at 6 AM.
Now, every time the event occurs, the alarm should launch the workflow and Notification Center should be disabled. As I mentioned earlier, Notification Center automatically re-enables each day at midnight. So, if you plan to schedule Do Not Disturb overnight, then you'll need to create an additional event that disables it again at 12:01 AM.
Building a Workflow to Disable Do Not Disturb (i.e. Re-Enable Notification Center Alerts and Banners)
Now that you've got a workflow to disable Notification Center, you probably want one to re-enable it.
1. Create another new Calendar Alarm workflow in Automator.
2. Search the action library for the Run AppleScript action again and drag it to the workflow area.
3. This time, replace the existing placeholder script in the Run AppleScript action with the following code:
This code updates Notification Center's property list file to disable Do Not Disturb. Then, it relaunches Notification Center for the change to take effect.
4. The workflow is done, so save it as Disable Do Not Disturb.
5. The Calendar app should launch again and another event should be added to the Automator calendar. This event should be configured with an Open File alarm that's set to open the Disable Do Not Disturb workflow. Set it to run on the desired schedule, such as every weekday morning at 9 AM.
If everything has gone according to plan, you should now have Do Not Disturb workflows that disable and re-enable Notification Center alerts and banners at the desired times. Use your alert-free time wisely. Until next time, happy scripting!
Subscribe to Newsletter
Software Updatesmore updates
- IFTTT adds a location channel to its iOS App
- Plants vs. Zombies 2 gets upgraded map, more 'cool' stuff
- Remote Desktop update brings OS X Mavericks support and improved multi-display support
- Valve revamps Steam Mobile for iOS
- Google Drive iOS app finally lets you sort items and find and replace in documents
- Viber announces Viber Out calls for iOS, goes head to head with Skype