Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'An AppleScript to periodically check all IMAP folders' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An AppleScript to periodically check all IMAP folders
Authored by: vrillusions on May 11, '05 11:06:18AM
jaysoffian's script didn't seem to work for me (haven't tried it till I upgraded to tiger). So I just took his idea with the original code that works and just added a check to see if mail is running. here's the code:

on checkMail()
	tell application "Mail"
		set everyIMAPAccount to every imap account
		repeat with eachIMAPAccount in everyIMAPAccount
			tell eachIMAPAccount
				-- cycle online status of each enabled and online account,
				-- causing mail to update the status for each folder
				if (enabled and include when getting new mail) then
					set include when getting new mail to false
					set include when getting new mail to true
				end if
			end tell
		end repeat
	end tell
end checkMail

-- Loops until the background activity of Mail has stopped
on waitForNoBackgroundActivity()
		tell application "Mail"
			if (background activity count is equal to 0) then
				exit repeat
				delay 5
			end if
		end tell
	end repeat
end waitForNoBackgroundActivity

-- Checks if Mail is running
on IsMailRunning()
	tell application "System Events"
		set procCount to name of every process whose name is "Mail"
	end tell
	if procCount is {"Mail"} then
		return true
		return false
	end if
end IsMailRunning

on run
	if IsMailRunning() then
	end if
end run

on idle
	if IsMailRunning() then
	end if
	return 300
end idle
Save it as an application bundle and do the same thing as above. cd into the and add the following two lines:

I've also noticed that if you modify the script and resave it, it moves that key further down, but it does still have it. Then just set it to start at login and it will do it's magic whenever mail is running, but only when mail is running. I've only tested this in 10.4 but don't see why it wouldn't work in 10.3

[ Reply to This | # ]