Created
April 19, 2013 10:47
-
-
Save amityweb/5419600 to your computer and use it in GitHub Desktop.
AppleScript to Move/Archive Mail Emails After Certain Number of Days
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on run | |
tell application "System Events" | |
set isMailRunning to (count of (every process whose bundle identifier is "com.apple.mail")) > 0 | |
end tell | |
if isMailRunning then | |
# Set Date the Mail is Old | |
set oldemaildate to ((current date) - (71 * days)) | |
# Call Handler for Archive Mailbox | |
archive_email("Email", "Archive", "Backup", "Backup/2013", oldemaildate) | |
# Call Handler for Sent Mailbox | |
archive_email("Email", "Sent", "Backup", "Backup/2013/Sent", oldemaildate) | |
end if | |
end run | |
# Handler to Archive the Email | |
on archive_email(target_account, target_mailbox, destination_account, destination_mailbox, oldemaildate) | |
tell application "Mail" | |
set _msgs_to_capture to (every message of mailbox target_mailbox of account target_account whose date received is less than oldemaildate and read status is true) | |
repeat with eachMessage in _msgs_to_capture | |
move eachMessage to mailbox destination_mailbox of account destination_account | |
end repeat | |
set selected mailboxes of message viewer 1 to {mailbox destination_mailbox} of account destination_account | |
end tell | |
end archive_email |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment