What you're looking for on OS X is scripting or "automation", and AppleScript. Here's the short story with some links to get you going:
Major applications (and certainly iTunes, with which I have some experience) expose "scripting dictionaries" of objects and methods and properties, etc, which can be accessed via a system scripting framework.
This is normally done by scripts in the AppleScript environment. AppleScript is a language, and it targets this underlying scripting infrastructure on OS X. You can wade into that here. There are other ways to talk to that scripting infrastructure, but you should understand up front that the AppleScript language, for better and worse, is really the only "first class" way of doing it, and so the semantics of how applications respond tends to be inextricable from how AppleScript talks to them. (More below)
Check out the "Script Editor" application (already installed on your Mac, just open it with Spotlight) which is the standard (though minimalist) user-level editor and try its File->Open Dictionary
command to inspect the dictionaries of some applications (like iTunes).
If you want to talk to iTunes from your application, though, and not from a one-off script of your own, you have a few options (these are easily confusable but actually fairly independent):
- The ObjC Scripting Bridge. This is a way of talking to an application by making it look like a native set of ObjC objects. I myself have found this the most convenient way of interacting with iTunes in a complex way, once you understand its quirks (the conceptual mapping is not exact), but opinions here will vary.
- AppleScriptObjC is a technology that lets you actually write entire parts (classes) of your Cocoa application in AppleScript directly. I see this as more useful for proficient AppleScript programmers who want to wrap their functionality in a first-class Mac app, not for what you describe.
- You can execute chunks of AppleScript from within Cocoa by using the NSAppleScript class. Useful if the thing you want to do with iTunes has a fairly limited surface area and is better or more easily expressed using AppleScript.
I don't know what complexity you're looking at for iTunes interaction, but here are some important things to know as you get started:
- AppleScript can be a beast of a language to get to grips with if you're already an experienced programmer. It is capable of some surprising expressiveness, but it's old, crufty and designed for non-programmers (thus confusing for programmers expecting clear grammar and familiar semantics). It's poorly documented with a fairly limited community around it. It continues to limp along, but beware that Apple doesn't give it much love.
- If you want to do anything nontrivial, even from Scripting Bridge, learn AppleScript first. The semantics will be the same and will make little sense from the Scripting Bridge side if you don't grok how they'd map to AppleScript. Again, AppleScript remains the only first-class way to talk to apps through their scripting interfaces. I have found Late Night's Script Debugger product invaluable for tracing through AppleScript while learning.
- Important tip as you learn: AppleScript (and especially the Scripting Bridge) present a view of an app that appears object-oriented: objects, methods, properties. But this is a convenient and seductive fiction; it's an abstraction that sits on top of the actual IPC mechanism, called Apple Events. Especially if you're coming from something like COM, the faster you understand the ways in which scripting is really an events+query system (and not an OOP interface), the faster you'll figure out how to get around it efficiently.
- App support for scripting is inconsistent, incomplete, poorly documented, and buggy. I can vouch for this in iTunes, which is probably better than most. Be prepared to hit and work around all sorts of surprising iTunes behavior. Feel free to ask questions on SO as you get to them; there are a handful of very knowledgeable folks who lurk here.