Automatically disable unused accounts in Mail
Apr 02, '08 07:30:00AM
Contributed by: Anonymous
I use two email accounts, a personal Gmail (IMAP) account, and a work mail account (also IMAP). I can only access my work email from within my work network, as the server is not on the internet. So I whipped up the following AppleScript and Launch Agent to automatically disable my work account when I'm not at work.
The script checks to see if Mail is running, if it is, and it has not been running for longer than five seconds (of processor time), then it checks to see if the server work-server is available, and enables/disables the Mail account Work as appropriate. Obviously, you'll need to customize those values for your situation.
Here's the AppleScript:
We also need a way to run this AppleScript automatically; for that we create a Launch Agent:
Save the above as net.checkmail.servers.plist in your user's Library » LaunchAgents folder, and it will run automatically when Mail's plist changes (which happens every time you launch Mail). Good luck!
[robg adds: I haven't tested this one, and note you'll need to edit both code snippets to match your setup.]
Mac OS X Hints