[Pythonmac-SIG] Controlling Mail.app from Python

Daniel Lord daniellord at mac.com
Sun May 28 16:12:42 CEST 2006


On May 27, 2006, at 21:26, Marcin Komorowski wrote:

> Is there a way to control Mail.app application from within Python the
> way it can be controlled using AppleScript?

Explore the appscript module (http://freespace.virgin.net/ 
hamish.sanderson/appscript.html).
I have found it to be powerful and very 'pythonic' once you  
understand the syntax which can be nearly every bit as arcane  
AppleScript itself since it must follow AppleScript.
the site has a lot of examples and there is a wiki or sorts.

I have successfully used it to control Mail, AddressBook, iTunes,  
BBEdit, and OminOutliner Pro. MS Excel has proven to be fairly  
problematic but I don't think it is appscript's fault--AE support is  
quite uneven and parochial from my experience--few outside of Apple  
implement it entirely correctly. Barebones, Late Night, Omnigroup,  
and Adobe seem to though.

The one thing I haven't succeeded in doing was to create a pure  
Python mail filter. I had to write an AppleScript hack that used the  
last word in the mail filter title as the name of a Python script to  
run and pass it the rule name and message id on the command line. But  
that is more a limitation of Apple Mail's external script invocation  
capability than its AppleScript implementation.

Daniel








More information about the Pythonmac-SIG mailing list