-
-
Save thesamprice/78471290e153debe813f9c7d1c053cc3 to your computer and use it in GitHub Desktop.
-- 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 {""} | |
im trying to run it but im getting this error:
tell application "Microsoft Outlook"
get current messages
--> {}
get selected folder
--> missing value
Result:
error "Can’t get name of missing value." number -1728 from name of missing value
I think the problem is somewhere here in this line but its out of my area of expertise:
set theName to name of mb
Any ideas what's up with this? im using outlook (the new modern look)
This was almost perfect. It helped a lot, but I still have lots of identical emails. Somehow they are different but I cannot identify where. Can you help?
I got duplicate since I changed email providers (GOOGLE to Microsoft) the message-ID seams different therefore I need to modify the way to identify duplicates. Can someone help?
Thank you so much. Lifesaver
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.
Thank you so much for this!!