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: jaysoffian on Feb 24, '04 05:27:42PM
I've improved the script, made it hidden (so I don't have to see it), and it now starts as a login item. First, here's the new script:

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"
		repeat
			if (background activity count is equal to 0) then exit repeat
			delay 5
		end repeat
	end tell
end waitForNoBackgroundActivity

on run
	tell application "System Events"
		if exists (application processes whose name is "Mail") then
			my waitForNoBackgroundActivity()
			my checkMail()
		end if
	end tell
end run

on idle
	delay 120
	tell application "System Events"
		if not (exists (application processes whose name is "Finder")) then quit
		if exists (application processes whose name is "Mail") then
			my waitForNoBackgroundActivity()
			my checkMail()
		end if
	end tell
	return 0
end idle
Cut and paste into Script Editor. Then save it as an Application Bundle. Open up the terminal and navigate to whever you saved the application bundle. Inside the bundle, edit Contents/Info.plist. Add to the top of the plist:

        <key>NSUIElement</key>
        <string>1</string>
So the top of your Info.plist now looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>NSUIElement</key>
        <string>1</string>
Now edit your login items and add the script (application bundle) as a login item. Logout and log back in. The script should now start on login, it will kill itself automatically on logout. You won't see it running unless you look for it from the terminal using the "ps" command or via the Process Viewer. And whenever Mail.app is running, any online IMAP accounts will now have all their folders updated when new messages are received to those folders.

[ Reply to This | # ]
An AppleScript to periodically check all IMAP folders
Authored by: cblackst on May 27, '04 11:56:33AM

Is there any way with the lastest script to have Mail.app actually display which folders have new messages without having to select the folder?

As I have it now, I have to select a folder to see the new email messages in it.

It's almost easier to just go offline/online with a keyboard shortcut



[ Reply to This | # ]
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()
	repeat
		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
	else
		return false
	end if
end IsMailRunning

on run
	if IsMailRunning() then
		checkMail()
	end if
end run

on idle
	if IsMailRunning() then
		waitForNoBackgroundActivity()
		checkMail()
	end if
	return 300
end idle
Save it as an application bundle and do the same thing as above. cd into the check_all_imap.app/Contents/Info.plist and add the following two lines:

        <key>NSUIElement</key>
        <string>1</string>
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 | # ]