Re: How to get music list?
Re: How to get music list?
- Subject: Re: How to get music list?
- From: Eric Lee <email@hidden>
- Date: Mon, 4 Aug 2008 16:38:45 -0500
On Aug 4, 2008, at 3:51 PM, has wrote:
Eric Lee wrote:
I have a problem getting the iTunes list, and then making the
tableview display the iTunes list.
Using objc-appscript [1], here's how to list the name, artist and
album of every track in the current playlist:
#import "ITGlue/ITGlue.h"
// To create glue files: osaglue -o ITGlue -p IT iTunes
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
ITApplication *itunes = [ITApplication applicationWithBundleID:
@"com.apple.itunes"];
ITReference *tracks = [[itunes currentPlaylist] tracks];
/* Note: if player is stopped then current playlist isn't available.
* You could either test for this in advance (as shown here) or check
* for nil results after sending the 'get' events. Additional NSError
* info is also optionally available.
*/
if ([[[tracks exists] send] boolValue]) {
/*
* Note: Apple event IPC is query-based, allowing you to get a
* property from all elements at once. This is far quicker than
* iterating over elements yourself if there are lots of them.
*/
NSArray *names = [[tracks name] getList];
NSArray *artists = [[tracks artist] getList];
NSArray *albums = [[tracks album] getList];
int i;
for (i = 0; i < [names count]; i++)
printf("%-60s %-60s %-60s\n", [[names objectAtIndex: i]
UTF8String],
[[artists objectAtIndex: i] UTF8String],
[[albums objectAtIndex: i] UTF8String]);
} else
printf("Current playlist is not available.\n");
[pool drain];
return 0;
}
HTH
has
[1] Which is a bit like Scripting Bridge, but without the
application compatibility problems and with 10.3.9 and 10.4.x
support, better documentation and developer tools.
--
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