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.

21 thoughts on “Outlook 2011 and OS X Notification Center Integration”

  1. Hey Matt,

    I am looking to get this setup on my Mac as well. Thanks for sharing the script but it doesn’t work for me. I think I have followed your instructions okay. How can I troubleshoot?

    thanks.

  2. Loukik,

    First of all, I would recommend creating the .scpt file with the AppleScript Editor under /Applications/Utilities/ instead of a text editor. That will let you know if there are any formatting issues with the script.

    If you don’t see any issues with the formatting of the file, then you can try mimicking my configuration:

    I have the content above saved as Notify New Mail.scpt in the /Users/andy.couch/Documents/Microsoft User Data/Outlook Script Menu Items/ folder.

    Then in Outlook, I have the following rule:

    When a new message arrives: [If all conditions are met]
    [All Messages]

    Do the following:
    [Run AppleScript] (select the the “Notify New Mail.scpt” file with the “Script…” button)

    [ ✓ ] Enabled

    If you still can’t get it to work, let me know and we can try to troubleshoot further.

  3. Okay, I figured it out! It works!!!!

    For my versions of OS (Mavericks) and Outlook (14.4.2), the script needed to be updated. Here is what I used. Maybe you want to add it to your page. Thanks a lot for your help. This is great!


    -- Get a list of all "current messages" in Outlook.

    tell application id "com.microsoft.Outlook"
    set currentMessages to current messages
    end tell

    -- Loop through the messages.
    repeat with eachMessage in currentMessages
    tell application id "com.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 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

  4. Glad you got it working! I’m using Mavericks with Outlook 14.4.1 and didn’t have any problem, but I will try updating to 14.4.2 and see if I have a problem and update the original script if necessary.

    For anyone else reading these comments, the change was replacing…

    tell application "Microsoft Outlook"

    …with…

    tell application id "com.microsoft.Outlook"

    …in two locations.

  5. Hi,

    I am trying to set the rule, but running a script isn’t an option in the drop down menu?

    Outlook 14.4.3
    OSX 10.9.4

  6. I get a lot of HTML emails, so I added this line to create a cleanContent version of the body, and send that to the notification system.

    set cleanContent to do shell script (“echo ” & (quoted form of messageContent) & ” |textutil -format html -convert txt -stdin -stdout”)

  7. Scott, I get a lot of HTML email as well and just using “set messageContent to plain text content of eachMessage” has always been enough for me, but thanks for the tip!

  8. Love this idea, however, I dont have “runapplescript” as an option in the Outlook dropdown. I am using Outlook 14.4.5 on Yosemite 10.10.

    Any idea?

  9. Worked great. Thanks for posting! I used your line “set messageContent to plain text content of eachMessage” and it looks clean and works smoothly.

    Clint, you may have been trying to add the rule on the exchange server side… I didn’t see the option when i first tried to add the rule but once I selected to add the rule “On My Computer”, I was able to select “Run AppleScript”

  10. I am trying to get this to work with Yosemitie OS. My version of Outlook is 14.4.6.

    I did the script and set it up but now messages.

  11. How could this script be modified to open the actual message (in Yosemite) if the user clicks on the banner or the “Show” option (if it’s displayed as an alert)?

  12. Hello. Outlook rule execution is generating an error.

    OS X 10.9.5
    Outlook for mac 2011: 14.3.0 (121105)
    Used both the original and Loukik’s versions of the *.scpt file.
    Script located in: /Users//Documents/Microsoft\ User\ Data/Outlook\ Script\ Menu\ Items/outlook_osx_notification_integration.scpt

    Error from Outlook:
    Error
    —-
    While processing message “notif test 2” (ID 2345), the rule “Notification Center” could not be successfully executed. An unknown error has occurred in Outlook.

    Details
    —-
    The script could not be run.

    Error code: -1752

    Any ideas on how to debug.

    Thanks,

    Jamie

  13. Hi,
    I tried this script and in the AppleScript editor I get an error on the word “notification” on the second line of the “– Display Notification” section:
    the error is: Expected end of line but found identifier.

  14. OS 10.10.2
    Outlook 14.4.8

    I had to add the following lines in between the “repeat with eachMessage…” and “tell application id…” in order to scope the variables so that they’re visible outside the “tell/end tell” scope

    set displayNotification to false
    set messageSubject to “”
    set messageSender to “”
    set messageContent to “”

  15. Hello hello, I have a new error message to report, and hope you can help me. iMac late 2013, yosemite 10.10.3

    “the rule “mail” could not be successfully executed. The script encountered error “Microsoft Outlook got an error: Can’t get «class PlTC» of incoming message id 4757.” during execution.”

    “mail” is the name i gave to the rule, and I ran the script as you had instructed. Any thoughts will be much appreciated.

  16. Hi, code works great!

    Wondering how the code can be changed to:
    – Pop up only shows Sender + Subject
    – Notification Centre shows Sender + Subject + Content

Leave a Reply

Your email address will not be published. Required fields are marked *