[Pythonmac-SIG] iTunes query
njriley at uiuc.edu
Sun Jul 27 22:31:07 CEST 2008
On Sun, Jul 27, 2008 at 01:50:52PM -0400, David Blackman wrote:
> I'm trying to figure out how AOEM queries work on iTunes, the code I'm
> trying looks like:
> for track in
> (I'm trying to find all the tracks in my library with the string "Sun"
> in the title)
> what am I doing wrong?
You're trying to use Python string and iterable methods on an
appscript reference. Because the remote process is doing the query,
you're limited to specifying which it knows how to evaluate. Once you
specify the query, you can then call .get() or just invoke the last
I generally find these things are easier to express in AppleScript
(scary, I know), so I use ASTranslate. For example, if I type into
tell app "iTunes" to get tracks whose name contains "Sun"
I get back:
And the expression is ready to use:
In : app(u'/Applications/iTunes.app').tracks[its.name.contains(u'Sun')].name()
u'Wasted Early Sunday Morning',
u'The Sun Is Burning',
although you're better off using app(id='com.apple.iTunes') of course.
Nicholas Riley <njriley at uiuc.edu> | <http://www.uiuc.edu/ph/www/njriley>
More information about the Pythonmac-SIG