Activate a Mail Rule via Applescript

I’ve searched and haven’t found anything that was answered, but what I’d like to do is this.

I have an IMAP account that I use with my iPhone and my MacBook Pro (running Leopard). I’ve got a Mail Rule that will move messages over 7 days old from my server to a local mailbox. The rule works great and does what I want with the exception of automation. What I’d like to do is with an apple script in iCal, run this Rule automatically in my mailbox. I guess another thing that would have to happen is a select all messages in mailbox as part of the automation. I’m currently doing that first and then “applying rules”.

Any thoughts?

Hi and welcome.

An easier way is to write an AppleScript to move the messages and trigger it
by iCal, launchd or run it every time at startup.

I’m using myself a similar script as a part of a larger startup script

I need help with the script, is it one you could provide or give me a link to?

try something like this


tell application "Mail"
	set theMessages to (get messages of mailbox "INBOX" of account "myAccount.com" whose date received < (current date) - weeks)
	repeat with oneMessage in theMessages
		move oneMessage to mailbox "destinationMailbox"
	end repeat
end tell

This works great, thanks.