In Eudora, and some other email clients, accounts can be set to automatically check for new mail on a per account custom interval. Apple Mail has only a global automatic check setting, on only a limited number of intervals. I have several accounts, some of which are not urgent, some of which get a lot of spam, and some which I'd like to check often, without having to wait for all others to check, and some of which I use only for sending, so I don't want to check them at all.
This is a feature I really missed from other email clients like Eudora. To try to duplicate this behavior, I set Mail to Manual checks and created an AppleScript to check accounts at arbitrary intervals. First I ran the following script to get a list of all accounts with an integer for each, formatted in a readable way.
--get list of accounts to assign to theAccountList variable
tell application "Mail"
set theAccountList to "set theAccountList to ¬" & return & "{¬" & return as string
set theAccounts to accounts
set theAccountCount to count of theAccounts
set theSeperator to ","
set theCount to 0
repeat with eachAccount in theAccounts
set theCount to theCount + 1
if theCount = theAccountCount then
set theSeperator to ""
end if
set theString to name of eachAccount as string
set theLine to "{account \"" & theString & "\" of application \"Mail\", 0 }" & theSeperator & " ¬"
set theAccountList to theAccountList & theLine & return
end repeat
set theAccountList to theAccountList & "}" & return
display dialog "Account List:" default answer theAccountList
end tell
(*
Paste the result from the above script into the following script and set minute intervals for accounts (with 0 to indicate no check). This script should be saved as an Application Bundle with the Stay Open option checked.
The previous version of this mail checking script would only quit with Command + period, but thanks to some research and coding by Ted, it will now respond to a Command + Q to quit, and will quit when the user is logged out or the machine is Shut Down or Restarted. Ted also added a command to Hide the script with Command H using System Events. I like the option but I sometimes prefer to leave the script visible, so I added a boolean to turn that option on or off.
The previous version of the script was an endless repeat loop with a delay and no "on idle" handler. That's why the "on quit" handler wouldn't work, the script never returned control to the handlers from the endless loop. Having the "on quit" handler work is good, because the previous version would keep running and cancel a logout.
*)
(*
PURPOSE:
Check individual Apple Mail accounts at different intervals that you determine.
INSTRUCTIONS:
Set Mail's preferences to "Check for new mail: Manually".
Save this script as an Application Bundle and select the Stay Open option.
*)
global theMinimumInterval, theAccountList, theMinuteCount, ScriptName
set hideDockIcon to false
set checkMailOnRun to false
set scriptPath to path to me
-- Get full name of this script.
tell application "Finder"
set scriptNameFull to name of scriptPath
set theExt to name extension of scriptPath
end tell
-- Get the name of this script, minus the extension
if theExt is not "" then
set ScriptName to (text items 1 thru -(2 + (length of theExt)) of scriptNameFull) as string
end if
if hideDockIcon then
-- Hide this script
tell application "System Events"
tell process ScriptName
keystroke "h" using command down
end tell
end tell
end if
tell application "Mail"
if checkMailOnRun then
activate
check for new mail
end if
set theMinimumInterval to 0
set theAccountList to ¬
{¬
{account "work" of application "Mail", 5}, ¬
{account "personal" of application "Mail", 20}, ¬
{account "spamtrap" of application "Mail", 180}, ¬
{account "sending-account" of application "Mail", 0} ¬
}
set theCount to 0
repeat with eachAccount in theAccountList
set theInterval to item 2 of eachAccount
if theInterval ≠ 0 then
set theCount to theCount + 1
if (theCount > 1) then
set theMinimumInterval to my gcd(theInterval, theMinimumInterval)
else
set theMinimumInterval to (theInterval as integer)
end if
end if
end repeat
if theMinimumInterval = 0 then
display dialog "No accounts will be checked (at least one value needs to be greater than 0)."
return
end if
end tell
set theMinuteCount to 0
on idle
set theMinuteCount to theMinuteCount + theMinimumInterval
repeat with eachAccount in theAccountList
set theAccount to item 1 of eachAccount
set theInterval to item 2 of eachAccount
if theInterval ≠ 0 then
set theMod to theMinuteCount mod theInterval
if (theMod = 0) then
tell application "Mail" to check for new mail for theAccount
end if
end if
end repeat
return (theMinimumInterval * 60)
end idle
on gcd(a, b)
repeat until b = 0
set x to b
set b to a mod b
set a to x
end repeat
return a
end gcd
on quit
continue quit
end quit
-- applescript page