Re: Trouble with Scripting Bridge
Re: Trouble with Scripting Bridge
- Subject: Re: Trouble with Scripting Bridge
- From: has <email@hidden>
- Date: Mon, 1 Sep 2008 18:38:27 +0100
Tommy Nordgren wrote:
On 31 aug 2008, at 03.12, Peter Stirling wrote:
I've been trying to do some python scripting of iTunes using pyobjc
and ScriptingBridge, and I've been having some problems (I reduced
everything to objective-c on its own in order work out if it was
caused by pyobjc).
[...]
However it doesn't seem to work, the code provided in the zip
archive (when executed on my machine), produces a list of all the
gapless tracks in my mp3 collection, but every line ALSO claims
that the track is 'not gapless'.
[...]
<tester.zip>
From test.m :
NSPredicate* predicate = [NSPredicate
predicateWithFormat:@"gapless=YES"];
this should probably be : ..... predicateWithFormat:@"gapless==YES"];
According to the NSPredicate Programming Guide, '=' and '==' are
synonyms so either should work in principle. That said, NSPredicates
don't actually function as NSPredicates in Scripting Bridge but are,
by some mysterious invisible magic, mapped to Apple event filter
clauses for the target application to handle. Given that there isn't a
1:1 correlation between NSPredicate and AE filter clause
functionality, this mapping is already somewhat lossy... and it's
always possible that it's buggy as well.
At any rate, filtering for gapped/gapless tracks seems to work fine in
AppleScript and appscript (or as well as most things work in iTunes
scripting), so at least it isn't an iTunes bug, e.g.:
#!/usr/bin/python
from pprint import pprint
from appscript import *
tracksref = app('iTunes').library_playlists[1].tracks
ref = tracksref[its.gapless == True]
if ref.exists():
pprint(zip(ref.album(), ref.id(), ref.gapless()))
else:
print 'No gapless tracks found.'
ref = tracksref[its.gapless == False]
if ref.exists():
pprint(zip(ref.album(), ref.id(), ref.gapless()))
else:
print 'No gapped tracks found.'
(Bear in mind that the above may take a few seconds for extremely
large playlists; depending on how you want to pick/organise/play your
random tracks there may be more efficient ways of approaching the task.)
HTH
has
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden