• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to get music list?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Re: How to get music list? (From: has <email@hidden>)

  • Prev by Date: Re: CoreFoundation Command Line Tool - an easy beginner question
  • Next by Date: Re: Automatic population of NSTableView with custom columns at launch time
  • Previous by thread: Re: How to get music list?
  • Next by thread: Terminate App While NSSheet Is Visible?
  • Index(es):
    • Date
    • Thread