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

Automatically disable unused accounts in Mail Apps
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.

Here's the AppleScript: 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.

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.]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[7,417 views]  

Automatically disable unused accounts in Mail | 5 comments | Create New Account
Click here to return to the 'Automatically disable unused accounts in Mail' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Automatically disable unused accounts in Mail
Authored by: dfbills on Apr 02, '08 10:21:31AM

Great script!

---
-d



[ Reply to This | # ]
Automatically disable unused accounts in Mail
Authored by: M. Sundbom on Apr 03, '08 08:06:26AM

I get the Applescript to work if run manually. I changed "enabled" to "include when getting new mail" because I still might want to browse the "offline" account but don't want Mail to automatically check for new mail.
However, I can't get the Launch Agent to work. Is there anything else than "username" in the path that need to be changed?



[ Reply to This | # ]
Automatically disable unused accounts in Mail
Authored by: mathieson on Apr 04, '08 08:46:44AM

Are you saving the plist file in "/Users/username/library/Launch Agents" ???
Did you change the path to the script in the plist according to where you put the applescript?

Bear in mind you need to log out then back in again to load the launch agent.



[ Reply to This | # ]
Automatically disable unused accounts in Mail
Authored by: M. Sundbom on Apr 07, '08 06:12:36AM

"Bear in mind you need to log out then back in again to load the launch agent."

Thanks, that made the trick.



[ Reply to This | # ]
Automatically disable unused accounts in Mail
Authored by: akulbe on Aug 18, '11 10:58:12PM

Does this still work with Lion? If not, can you share how this would need to be modified to work with Lion?

I'm trying to do something like this, because my work email server isn't reachable off the LAN, and I'd like to drop my work account into Mail.app and not have to deal with the incessant errors when I leave the office. :)



[ Reply to This | # ]