Re: Delete Mail Script
Re: Delete Mail Script
- Subject: Re: Delete Mail Script
- From: Deivy Petrescu <email@hidden>
- Date: Wed, 07 Aug 2013 16:10:45 -0400
On Aug 6, 2013, at 20:02 , Robert <email@hidden> wrote:
> Hello Applescript List members;
>
> First time poster and relative newbie here.
>
> I've written a script that searches for messages, in a particular mailbox, that are older than a couple of days and then deletes them.
>
> The script generally works except I usually have to run it two or three times before it picks up ALL of the messages that fall into the
>
> 'older than 2 days' category.
>
> The snippet of relevant code is below and any pointers towards what may be wrong would be heavily appreciated.
>
> Btw - I'm running Mountain Lion and the included Apple Mail program. I have 4GB RAM and plenty free HD space.
>
> Thanks in advance
>
> Robert.
>
>
> tell application "Mail"
> set fetches automatically to false
> set selectedMessages to (messages of mailbox "Spam Virus Mail" of mailbox "Personal" whose date received is less than today - (2 * days))
> set messcount to (count of selectedMessages)
> if (count of selectedMessages) is equal to 0 then
> tell application "Finder"
> activate
> display alert "No mail in the Spam Virus Mail mailbox is older than 2 days" message "Try running this script later on. Rob." giving up after 2
> end tell
> else
> try
> repeat with i from 1 to messcount
> set theSource to item i of selectedMessages
> set background color of theSource to red
> delete theSource
> end repeat
>
You can make your life considerably simpler if you just delete the messages that you want to delete:
set j to 2 --how old you want your deleted messages to be
tell application "Mail" to delete (every message of mailbox "Spam Virus Mail" of mailbox "Personal" ¬
whose date received is less than ((current date) - (j * days)))
You can copy and paste the script in your ASEditor
Deivy Petrescu
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden