Tag Archives: applescript

Outlook 2011 and OS X Notification Center Integration

Microsoft Outlook 2011 was released before Mac OS X introduced the Notification Center, but you can still implement consistent OS notifications with the help of some AppleScript.

Simply save the following code as an AppleScript (.scpt) file and then create a rule in Outlook to run it when new mail arrives. Once you have confirmed it’s working, you can disable the built-in Outlook notifications.

-- Get a list of all "current messages" in Outlook.
tell application "Microsoft Outlook"
  set currentMessages to the current messages
end tell

-- Loop through the messages.
repeat with eachMessage in currentMessages
  tell application "Microsoft Outlook"
    -- Only notify about unread messages.
    if is read of eachMessage is false then
      set displayNotification to true
      set messageSubject to get the subject of eachMessage
      set messageSender to sender of eachMessage
      set messageContent to plain text content of eachMessage
      -- Get an appropriate representation of the sender; preferably name, but fall back on email.
      try
        if name of messageSender is "" then
          set messageSender to address of messageSender
        else
          set messageSender to name of messageSender
        end if
      on error errorMessage number errorNumber
        try
          set messageSender to address of messageSender
        on error errorMessage number errorNumber
          -- Couldn’t get name or email; we’ll just say the sender is unknown.
          set messageSender to "Unknown sender"
        end try
      end try
    else
      -- The message was already read, so we won’t bother notifying about it.
      set displayNotification to false
    end if
  end tell
  
  -- Display notification
  if displayNotification is true then
    display notification messageContent with title messageSender subtitle messageSubject
    -- Allow time for the notification to trigger.
    delay 1
  end if
end repeat

Note: This script is based on a Growl notification script for Outlook by Matt Gemmell, which was based on an Entourage script he found on the internet.