• 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: Gregory Weston <email@hidden>
  • Date: Tue, 26 Jun 2007 11:30:38 -0400


On Jun 25, 2007, at 5:52 PM, John Stiles wrote:

On Jun 25, 2007, at 12:26 PM, Gregory Weston wrote:

Angelo Chen wrote:

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

tell application "iTunes" to add (POSIX file "thePath") to (first library playlist)


Wrap that in an NSAppleScript, with thePath replaced by the full path of the track you want to add.

Be careful—this will not work if the path contains any non-MacRoman characters. (Which means that in many countries it will never work.)
The fix involves replacing "thePath" with a goofy hack/workaround that looks like this:


(«data utf84142434445464748» as Unicode text)

You plug in hexadecimal numbers corresponding to the path string, in UTF8, after the 'utf8' bit.
I wish there were a simpler way…

Faced with that information, I've decided I think this is the simpler way:


- (void)importMusicFile:(NSString*)inPath
{
const char* kTemplate = "'insh':'obj '{form:indx, want:type(cLiP),"
"seld:long(1), from:'null'()}, '----':alis (@@)";


CFURLRef theFileURL = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,
(CFStringRef)inPath,
kCFURLPOSIXPathStyle, false);
if(theFileURL)
{
FSRef theFileRef = {};
if(CFURLGetFSRef(theFileURL, &theFileRef))
{
AliasHandle theFileAlias = NULL;
OSStatus theStatus = FSNewAlias(NULL, &theFileRef,&theFileAlias);
if(theStatus == noErr)
{
OSType theSignature = 'hook'; // The app signature for iTunes
AppleEvent theRequest = {typeNull, NULL};
AEBuildError theBuildError = {};
theStatus = AEBuildAppleEvent('hook', 'Add ', typeApplSignature,
&theSignature, sizeof(OSType),
kAutoGenerateReturnID, kAnyTransactionID,
&theRequest, &theBuildError, kTemplate,
theFileAlias);
if(theStatus == noErr)
{
AppleEvent theReply = {typeNull, NULL};
theStatus = AESendMessage(&theRequest, &theReply, kAEWaitReply,
kNoTimeOut);
if(theStatus == noErr)
{
(void)AEDisposeDesc(&theReply);
}
(void)AEDisposeDesc(&theRequest);
}
DisposeHandle((Handle)theFileAlias);
}
}
CFRelease(theFileURL);
}
}


I'd rather do that than build that data block. Feel free, anyone who wants to use it.

G_______________________________________________

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: Adding files to iTune library in Cocoa app (From: Gregory Weston <email@hidden>)
 >Re: Adding files to iTune library in Cocoa app (From: John Stiles <email@hidden>)

  • Prev by Date: Core Data training
  • Next by Date: Re: Drawing from upper left
  • 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