I want to archive old emails ( say, older then 7 days ) from my inbox automatically with an applescript scheduled via cron.

To be honest, I am open to other Apple-friendly languages such as Swift or Coco , though the learning curve might be prohibitive for me.

Ideas, Examples, and links relevant to the topic are welcome.

  • 1
    Welcome to Ask Different. What have you tried so far? Have you investigated the rules built into Mail? Please review How do I ask a good question? for tips on writing questions that get good and relevant answers. Cheers, – bjbk Jan 25 '16 at 1:11

To start with, you can try this Applescript:

set interval to 7
set target to (current date) - interval
set oldCount to 0
tell application "Mail"
    set box to mailbox named "INBOX" of account named "Your_mailbox_here"
    set maxMessages to count of messages in box
    repeat with index from 1 to maxMessages
        set currentMessage to message index in box
        set msgDate to date received of currentMessage
        if msgDate is greater than target then
            set oldCount to oldCount + 1
            # do something here
        end if
    end repeat
end tell

Enter the above script in Script Editor, play with it till it does what you want, then save it as a script file (.scpt). run it with osascript(1).

Look at Applescript Resources and the Applescript Language Guide for more useful info. Also look at the scripting dictionary of Mail.app using the "Open Dictionary..." command in Script Editor to see what sort of things you can script in mail.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .