Created
May 18, 2017 20:27
-
-
Save AndyCouch/4f4e94812921aa2ce78b81c74645e356 to your computer and use it in GitHub Desktop.
AppleScript for Outlook 2011 and OS X Notification Center Integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment