3

I am building a Mac OS Application which needs to import an mp3 file into iTunes...

Can't seem to find any framework that would help me achieve this. The only way I can think of doing this is modifying the "iTunes Music Library.xml".

I'm hoping one of you can point me to a better and cleaner solution.

Thank you in advance.

MiMo
  • 4,905
  • 3
  • 22
  • 23
  • 4
    Feeling a bit too lazy to type out a complete answer, but take a look at [Scripting Bridge](http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ScriptingBridgeConcepts/UsingScriptingBridge/UsingScriptingBridge.html#//apple_ref/doc/uid/TP40006104-CH4-SW1), which lets you talk to AppleScriptable apps using Objective-C. It's pretty slick. One of the pieces of sample code in those docs is to talk to iTunes. – Andrew Madsen Jul 01 '13 at 21:37
  • Thanks Andrew! I'll take a look at it now. – MiMo Jul 01 '13 at 21:41

1 Answers1

7

Ok, so after some research on Scripting Bridge, just like Andrew Madsen suggested. Here is the answer to my own question.

This has been implemented and tested...

  1. Add the ScriptingBridge Framework to your Mac OS Project.
  2. Generate the iTunes.h file by writing the following in the terminal.

    sdef /Applications/iTunes.app | sdp -fh --basename iTunes

  3. Import the newly created iTunes.h file into your Mac OS Project and do an #import "iTunes.h" in the class you would like to use the Scripting Bridge in.

  4. Use this code to add a song to iTunes:

    iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"]; iTunesTrack * track = [iTunes add:[NSArray arrayWithObject:[NSURL fileURLWithPath:filePath]] to:playlist];

  5. That is all to it.

MiMo
  • 4,905
  • 3
  • 22
  • 23