Skip to content

Instantly share code, notes, and snippets.

@edenwaith
Last active January 21, 2024 13:52
Show Gist options
  • Save edenwaith/13a09a003fc019636828718ea7968fbe to your computer and use it in GitHub Desktop.
Save edenwaith/13a09a003fc019636828718ea7968fbe to your computer and use it in GitHub Desktop.
An AppleScript to go through the mailboxes in Outlook and mark unread messages as read
-- File: MarkUnreadEmails.scpt
-- Description: Go through the mailboxes in Outlook and mark unread messages as read
-- Author: Chad Armstrong
-- Date: 22 November 2019
tell application "Microsoft Outlook"
set myInbox to folder "Inbox" of default account
set github to folder "GitHub" of myInbox
set other to folder "Other" of myInbox
-- For GitHub give a few days for the cutoff threshold
-- For Other, mark all as read immediately
my markUnreadMessages(github, 4)
my markUnreadMessages(other, 0)
end tell
on markUnreadMessages(targetFolder, cutoff)
tell application "Microsoft Outlook"
set cutoffTime to cutoff * days
set countUnreadMessages to count of (messages of targetFolder whose is read is false)
set theMessages to (messages of targetFolder whose is read is false)
set today to (current date)
set countEmailsRead to 0
set mailboxName to name of targetFolder
repeat with theMessage in theMessages
try
set messageTime to time received of theMessage
set messageAge to today - messageTime
if messageAge > cutoffTime and (is read) of theMessage is false then
set countEmailsRead to countEmailsRead + 1
set theMessage's is read to true
end if
on error errorMsg
log "Error: " & errorMsg
end try
end repeat
display notification "Outlook cleanup ran at " & today & " - " & mailboxName & ":" & countEmailsRead & " messages were marked as read from " & countUnreadMessages & " unread messages." with title "Email Cleanup" sound name "Sosumi"
-- log "Outlook cleanup ran at " & today & " - " & mailboxName & ":" & countEmailsRead & " messages were marked as read from " & countUnreadMessages & " unread messages."
end tell
end markUnreadMessages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment