python on mac (os x): application automation

Mitch Chapman mitchchapman at earthlink.net
Fri Sep 12 03:19:52 CEST 2003


Leo wrote:
> hi there
> 
> i have just started with mac development and i use applescript at the moment
> for iTunes and iPhoto automation.
> 
> but i'd like to do it from python. does anybody know weather  that's
> possible and if there is a add on for that?
> 
> thanks, leo
> 
> 

Bob Ippolito has built aeve for just such purposes.
He recently announced aeve 0.0.3; you can find the announcement
here:

http://mail.python.org/pipermail/pythonmac-sig/2003-September/008692.html

Because I am lazy and do not read documentation :) I just downloaded
all of the source distributions from his website.  He also provides
binary distributions, which can be installed using PackageManager.

To build aeve for Python 2.3 from source, you'll need to
download and install each of these tarballs, using the usual
'sudo python setup.py install' incantations:

http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/Pyrex-0.8.2.tgz
http://undefined.org/python/TECManager-0.1.tgz
http://undefined.org/python/LaunchServices-0.1.tgz
http://undefined.org/python/aeve-0.0.3.tgz

Bob's announcement includes sample code showing how to get the
name of the currently-playing iTunes track.  He also provided the
following variation, which works if you happen to be playing
no tracks:

#!/usr/bin/env pythonw
import aeve
iTunes = aeve.talkto('com.apple.iTunes')
if iTunes.player_state == 'playing':
     print iTunes.current_track.name
else:
     print "iTunes is not currently playing a track"

Please also note that, in order to use aeve, you will
probably need to invoke python as pythonw (or run from within
a MacPython IDE) so you can talk to the window manager.

--
Mitch





More information about the Python-list mailing list