So, I know practically nothing about scripting (a smidge of Javascript, and even less PHP), but I’m determined to modify Gruber’s
Simple Archiving Script for my own specific use. Grand Theft Code, no doubt, but I’d really like to get it working.
I only have one (IMAP) email account that I use, so I don’t think the “
repeat with _acct in imap accounts” section is required.
I have two specific modifications I want to make:
- I only want Mail to archive messages that are read, unflagged, and more than 14 days old; and,
- I want it to do the same thing in the “Sent” mailbox as well, but moving it to “Archive/Sent” mailbox instead of the “Archive/Inbox” folder.
I think the variable to determine the age of the emails should go where I’ve inserted the line of asterisks into the code. Unfortunately, I have no idea what the variable/instruction would be.
The second modification should be somewhat more straightforward, but I’m not sure how to do it without causing problems. Do I just insert the same code below the first set with the ‘inbox’ references replaced by ‘sent’? And how do I join the two pieces to make it run the inbox portion first, then the sent portion second?
Without further ado, the code I have thus far is:
Code:
set _description to "All unflagged, read messages in “Inbox” and “Sent” will be moved to the corresponding “Archive” mailbox. This action cannot be undone."
tell application "Mail"
display alert "Archive read messages from “Inbox” and “Sent” folders?" 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/Inbox"
on error
display alert "No “Inbox” folder found in “Archive” mailbox."
return -- Stop the script
end try
set _msg_list to (every message of _inbox ¬
whose flagged status is false and read status is true)
if (_msg_list's length > 0) then
*******************************************************
move _msg_list to _archive_box
end if
end repeat
end tell
Perhaps the most important question I can ask is this: can anyone recommend a really good book to learn Apple Script from?
Thanks in advance.
Edit: One final question I forgot to ask: is there any way of making the script run automatically every day at a set time?