Be notified by Mail only for a specific mailbox

Aug 08, '12 07:30:00AM

Contributed by: Anonymous

Mail notifications, while useful, can be overwhelming. That's why Mail can restrict the notifications (Dock badge and Notification Center) to a specific mailbox or Smart Mailbox.

Notifications restriction is available from Mail's Preferences; however here is a way to change this setting using a script, without going through the GUI.

This is especially useful when used with location-aware apps, such as Marco Polo or ControlPlane: you can automatically be notified of your professional e-mails only when at work, and of your personal emails only when at home, for instance.

I find it especially useful to keep focused and reduce the amount of distracting notifications.

#!/bin/bash
#
# Configure Mail.app to enable notifications only in the specified mailbox.
# Notifications include the Dock badge and messages in the Notification Center.
#
# Usage:
#   restrict-mail-notifications 
#
# Example:
#   restrict-mail-notifications smartmailbox://f687826d-f4de-4724-9a12-c5794dcdaa32
#
# Notes:
#   To find the mailbox id you're interested in, look in the com.apple.mail.plist file.
#

mailboxID="$1"

if [ ! -n "$mailboxID" ]; then
	echo "Error: "mailboxID" parameter missing."
	echo "Usage: $0 "
	exit -1
fi

# Only display the unread messages count in the Dock for the specified mailbox
defaults write com.apple.mail MailDockBadgeMailbox "$mailboxID"

# Only display notifications for incoming messages in the specified mailbox
defaults write com.apple.mail MailUserNotificationScope -int '4' # Smart mailboxes
defaults write com.apple.mail MailUserNotificationMailbox "$mailboxID"

# Now relaunch Mail.app for changes to take effect
[kirkmc adds: I haven't tested this.]

Comments (2)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20120802063503285