Hello Deivy, On Thu, 30 Jul 2009 16:33, Deivy Petrescu wrote: > Do everything in one pass: > > > tell application "Mail" > activate > set _selected to first item in (get selection) > set received to date received of _selected > set _mailbox to mailbox of _selected > set _range to messages in _mailbox whose date received ? received > > set _messageids to {} > > repeat with _i in _range > set _i to contents of _i > set _mid to message id of _i > if _mid is not in _messageids then > set end of _messageids to _mid > else > delete _i > end if > end repeat > end tell Thank you for this script. Yesterday, I could test this, first on my office computer (G5, running 10.5.7), and then my home machine (G4, running 10.4.11), and another one. Your code works very quickly, and in this sense, it is very good. But one problem is that it seems to delete the first duplicate message in the list. I would prefer that it is the last one. This is because I might have replied to the first one, which would have the "replied" mark. If I delete the first one, this "replied" (or other) mark will be lost... The other script that I tried is the following: tell application "Mail" activate set _selected to first item in (get selection) set received to date received of _selected set _mailbox to mailbox of _selected set _range to messages in _mailbox whose date received ³ received set last_id to "mydummy" repeat with _i in _range set this_id to message id of _i if this_id = last_id then delete (last_msg) end if set last_id to message id of _i set last_msg to _i end repeat end tell This works; it seems much slower than your script (it returns a bunch of message objects in a list), but it deletes that last message in the two consecutive duplicate messages. But it happened a very serious "accident": I tested several forms of the second script on my office computer, and finally, the one that I copy above seemed to work. Everything seemed OK at that moment. I backed up all the ~/Library/Mail folder in my portable disk, came back home, and restored it to my home computer. Then I opened Mail; after a while, it had an error message saying something like "The Index of messages is broken. To restore it, you must quit Mail, and relaunch it". I did so: it took a very long time to "Import" my mail boxes... And it could restore all the mail boxes. But I noticed that there were some (3 or 4) last messages which were lost... I could re- import them, using the web mail, and forwarding to myself the lost messages, but this caused a fear to me. -- I think I should have checked more closely when I finished testing my scripts, if there were no lost messages. And perhaps, I should have quit once Mail, and relaunch it, to have all the "Index" right. -- At least, I did so on my home computer, and now, it seems to work normally. But anyway, this made me somehow uneasy about the use of these (or this) scripts. -- I think/hope that this was caused my test scripts, which did not work well... Best regard, Nobumi Iyanaga Tokyo, Japan