[Pythonmac-SIG] iphoto, slow
hengist.podd at virgin.net
Fri Dec 2 01:00:27 CET 2005
Gábor Farkas wrote:
>i am trying to print out all my photo's names, together with their keywords.
>this code works, but it's TERRIBLY slow :)
>the problem is the parsePhoto function...
>those keyword.name(), photo.name(), photo.keywords() calls take nearly a
>second to complete...
That sounds really awful, though I don't have a scriptable copy of iPhoto to confirm it myself. (Smoked my copy of iPhoto 2.0 in the last reinstall and am too cheap to buy iLife, so am back on v1 now.) Quite possible though - I seem to recall reading complaints in the past about its GUI bogging down on large numbers of images, so may be more of the same problem.
>is there a better way to do this?
>perharps get the data about multiple photos at the same time?
Always a good idea to do that if you can. At the moment you're sending about the most commands you can. You could certainly reduce that a bit; perhaps right down to just two with a bit of luck: one to get all the photo names, and one to get all the keyword names for every photo. Not sure how well iPhoto can resolve more complex queries, but here's the code to try:
p = app('iPhoto')
print zip(p.photos.name(), p.photos.keywords.name())
If that doesn't work, let me know and I'll suggest ways to unroll it a bit.
BTW, the next release of appscript (whenever that is) will include a chapter on optimising code for efficiency; I just haven't gotten around to finishing it yet. FWIW, I've temporarily posted some of the notes here:
More information about the Pythonmac-SIG