• 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: Adding files to iTune library in Cocoa app
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding files to iTune library in Cocoa app


  • Subject: Re: Adding files to iTune library in Cocoa app
  • From: has <email@hidden>
  • Date: Mon, 25 Jun 2007 21:24:01 +0100

Angelo Chen wrote:

Is there a way to add files into iTune library in a Cocoa app?

You'll need to use Apple events to talk to iTunes. One option is to use NSAppleScript to execute AppleScript code within your application, although that gets tedious and fiddly for anything non- trivial:


http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ Classes/NSAppleScript_Class/Reference/Reference.html


Another option would be to use the AEBuild* suite of functions [2] to assemble and send the event, although this generally requires a bit of knowledge of low-level Apple event stuff:


	http://developer.apple.com/technotes/tn/tn2045.html

Or you could build and pack an Apple event using NSAppleEventDescriptor and dispatch it with AESendMessage, though again this requires some familiarity with Apple event stuff.


Yet another option is to use a high-level Apple event bridge like objc-appscript:


	http://appscript.sourceforge.net/objc-appscript.html

Instructions for getting and installing objc-appscript are on that page. Full documentation on how to create glue files and use appscript is included in the download. (BTW, if anything's unclear, just let me know as I'm planning a file release for next month.)

The following example uses appscript to add a file ('audio file.mp3') to a playlist named 'Pop'. (The 'to' parameter is optional, btw; if omitted, the file is added to the main Library playlist only.)

/*
 * To create glue files: osaglue IT iTunes
 */
#import <Foundation/Foundation.h>
#import "ITGlue.h"

int main (int argc, const char * argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
ITApplication *iTunes;
NSURL *file;
ITReference *playlist, *result;
ITAddCommand *addCmd;

iTunes = [[ITApplication alloc] initWithName:@"iTunes.app"];

file = [NSURL fileURLWithPath: @"/Users/foo/audio file.mp3"];
playlist = [[ITApp playlists] byName: @"Pop"];

// create command object
addCmd = [[iTunes add: file] to: playlist];

// send event and check for result or error
result = [addCmd send];
if (result == nil)
NSLog(@"iTunes error %i: %@\n", [addCmd errorNumber], [addCmd errorString]);
else
NSLog(@"New track reference = %@\n", result);

[iTunes release];
[pool release];
return 0;
}



HTH

has
--
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org
http://appscript.sourceforge.net/objc-appscript.html

_______________________________________________

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


  • Prev by Date: Re: HTTP Uploading
  • Next by Date: Re: Adding files to iTune library in Cocoa app
  • Previous by thread: Re: Adding files to iTune library in Cocoa app
  • Next by thread: Re: Adding files to iTune library in Cocoa app
  • Index(es):
    • Date
    • Thread