global theMinimumInterval
on run
tell application "Finder"
-- Get name of this script, minus the extension
set scriptPath to path to me
set scriptNameFull to name of file scriptPath as text
if (offset of "." in scriptNameFull) > 0 then
set ScriptName to (text items 1 thru -2 of scriptNameFull) as string
end if
end tell
end run
on idle
tell application "Mail"
set theMinimumInterval to 0
set theAccountList to ¬
{¬
{account "work" of application "Mail", 1}, ¬ -- this one works
{account "personal" of application "Mail", 2}, ¬ -- this one doesn't
}
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 have been set to check (values greater than 0)."
return
end if
set theMinuteCount to 0
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
check for new mail for theAccount
end if
end if
end repeat
return (theMinimumInterval * 60)
end tell
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