Created
October 9, 2019 15:12
-
-
Save thesamprice/78471290e153debe813f9c7d1c053cc3 to your computer and use it in GitHub Desktop.
Removes duplicate emails from MS outlook on mac.
This file contains 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
-- Remove Duplicate Message v2.1 | |
-- An Applescript based on code by Barry Wainwright, 15th October 2010 | |
-- Detects and deletes duplicate messages within a selected folder | |
-- works on Message-ID header - uniquely identifying duplicates | |
-- Version History | |
-- v1.0 - 2002-03-18: First Release (For Microsoft Entourage) | |
-- v2.0 - 2010-10-07: modified to work with Microsoft Outlook for Mac | |
-- v2.1 - 2010-10-15: added final dialog to summarise messages removed | |
-- v2.2 - 2019-10-05: Added progress bar. (Sam Price) | |
-- To use | |
-- open script editor, copy and paste this in. | |
-- save this file as RemoveDuplicates.scpt | |
-- Then open up microsoft outlook and select the folder you have duplicate emails in. | |
-- then click the play button. | |
set progress description to "Dup email remover" | |
set progress additional description to "Preparing…" | |
set progress total steps to -1 | |
tell application "Microsoft Outlook" | |
set theMessages to current messages | |
if theMessages = {} then | |
try | |
set theFolder to selected folder | |
set mb to theFolder | |
on error | |
display dialog "In the folder listing, please select the folder you want to be scanned for duplicates" with icon stop buttons {"Quit"} default button 1 | |
return -99 | |
end try | |
else | |
set mb to folder of item 1 of theMessages | |
end if | |
set theName to name of mb | |
say "Removing duplicates from mail folder: " & theName | |
set y to count messages of mb | |
end tell | |
set progress total steps to y | |
set cntDeleted to 0 | |
-- say "Number of messages to check, " & y | |
set IDlist to {} | |
repeat with x from y to 1 by -1 | |
tell application "Microsoft Outlook" | |
try | |
set theHeaders to (get headers of message x of mb) | |
set AppleScript's text item delimiters to {return & "Message-"} | |
set temp to text item 2 of theHeaders | |
set AppleScript's text item delimiters to {return} | |
set theId to text 5 through -1 of text item 1 of temp | |
on error | |
set theId to "" | |
end try | |
if theId is in my IDlist then | |
set cntDeleted to cntDeleted + 1 | |
delete message x of mb | |
else if theId ≠ "" then | |
copy theId to end of IDlist | |
end if | |
end tell | |
if x mod 50 = 0 then | |
set progress completed steps to y - x | |
set progress additional description to " " & x & " left of " & y & " Checked " & cntDeleted & " Deleted " | |
-- say "" & x | |
end if | |
end repeat | |
tell application "Microsoft Outlook" | |
set removedCount to y - (count messages of mb) | |
end tell | |
if removedCount is 0 then | |
-- say "Finished. No duplicates detected" | |
else | |
-- say "Finished. " & removedCount & " duplicates removed" | |
end if | |
display dialog "" & y & " messages checked" & return & removedCount & " messages removed" buttons {"OK"} default button 1 | |
set AppleScript's text item delimiters to {""} | |
If anyone has the issue:
Error "can't get name of missing value" set theName to name of mb (the word "name" is highlighted).
error "Can’t get name of missing value." number -1728 from name of missing value
This is because you have not opened outlook and clicked on the inbox you wish for the script to apply on. It took me a while to figure this out - the script goes and works on the inbox you have clicked in Outlook.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much. Lifesaver