Skip to content

Instantly share code, notes, and snippets.

@gaelicWizard
Forked from gruber/gist:1063605
Created July 17, 2011 21:38
Show Gist options
  • Save gaelicWizard/1088094 to your computer and use it in GitHub Desktop.
Save gaelicWizard/1088094 to your computer and use it in GitHub Desktop.
Simple Inbox Archiving Script for Apple Mail
-- See article here: http://daringfireball.net/2007/07/simple_inbox_sweeper
-- The following should be one long line:
set _description to "All unflagged, read messages in each IMAP account
inbox will be moved to the “Archive” mailbox corresponding to that
account. This action is not undoable."
tell application "Mail"
display alert "Archive read messages from IMAP inboxes?" buttons ¬
{"Cancel", "Archive"} cancel button 1 message _description
repeat with _acct in imap accounts
set _acct_name to name of _acct
set _inbox to _acct's mailbox "INBOX"
try
set _archive_box to _acct's mailbox "Archive"
on error
try
set _archive_box to _acct's mailbox "INBOX/Archived"
-- Some hosts nest all folders within INBOX, and some users fail to configure their prefix properly.
on error
try
set _archive_box to _acct's mailbox "Saved"
-- AOL's IMAP keeps everything in the Saved folder, but deletes old mail elsewhere.
on error
try
set _archive_box to _acct's mailbox "[Gmail]/All Mail"
-- Gmail always keeps all mail, but this gets it out of the inbox.
on error
display alert "No “Archive”, “Saved”, nor “[Gmail]/All Mail” mailbox found for account “" & ¬
_acct_name & "”."
return -- Stop the script
end try
end try
end try
end try
-- Begin update for OS X 10.7.0
set _msgs_to_move to (a reference to ¬
(every message of _inbox ¬
whose flagged status is false and read status is true))
set _msg_list to contents of _msgs_to_move
if (_msg_list's length > 0) then
move _msgs_to_move to _archive_box
end if
-- End update for 10.7.0
end repeat
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment