I need help with a script I have tried writing...

…I don’t know any Applescript… but from reading various others I thought I would try and cobble one together to get what wanted done… but, surprise surprise, it isn’t working.

I am trying to write a script that will delete mail from certain mailboxes once the mail is greater than two weeks old. This is what I have written…

tell application "Finder"
	delete (every item of folder "macintosh hd;users;lesturner;library;mail/mailboxesamazon.mbox;messages" whose modification date is less than ((get current date) - 14 * days))
end tell

BUt I am getting the error… “Finder got an error: Can’t get every item of folder “macintosh hd;users;lesturner;library;mail/mailboxesamazon.mbox;messages” whose modification date < date “Monday, 7 May 2007 9:29:51 PM”.”

What am I doing wrong and what can I do about it? I have tried figuring it out, but there is only so many tutorials I can do before I realise that they aren’t answering my question.

Thanks in advance.

I’m not trying to discourage you from learning Applescript, but I think in this case, you’d be better off to create a rule in Mail to handle this.

If you don’t know how, simply go under Mail>Preferences, then click the Rules tab. Select “Add Rule”.

  1. For the first condition, select “Account” from the dropdown, then select your account.
  2. Click the “Plus” button to add another condition.
  3. For the second condition select “Date Received”, then “Is Greater Than”, than “14” days (or whatever timeframe you wish).
    (if you wish to apply this to mutilple mailboxes, repeat step 2 then step 1)
  4. Then for “Perform the following actions”, select “Delete message”,
  5. Then hit “OK”. You’ll be asked if you want to apply this rule to all mailboxes, click “Yes”.

This should do exactly what you want.

slimjim5811