Controlling Music (iTunes) from a Mac OS Swift app.

Hi,

I'm working on an app based on the ITLibrary so I can get all the tracks info like their persistent ID and I'd like to play it in Music from my app.

I do it easily with AppleScript so do I need to use a bridge or can I do it directly from a Swift 4 app ?

Thx.

can I do it directly from a Swift 4 app ?

macOS has two ‘iTunes library’ APIs:

Both are available from Swift.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Yes I know about iTunes Library Framework because I spoke about it with the ITLibrary.

But like I said, we can't control the Music / iTunes app, only get its infos :

My question is about how to play a track in the Music / iTunes app from another app ?

Thx.

You will need to use Apple event IPC to control Music.app. Options:

• ScriptingBridge.framework – defective by design and effectively unsupported and abandoned; usually mostly works for trivial stuff, but breaks on a lot of tasks that work perfectly in AppleScript and generally not worth wasting time on

• AppleScript-ObjC bridge – allows you to wrap your AppleScript handlers as NSObject subclasses and call them directly from your Swift/ObjC code. Bridging numerical types is a little fiddly (you have to use NSNumber, not Bool/Int/Double primitives) and block-based APIs are unsupported, but this is by far the least awful option and the one I recommend. Example project here: github.com/hhas/Swift-AppleScriptObjC

(There is also SwiftAutomation, which unlike Apple’s ScriptingBridge actually works right, but I haven’t used or maintained it in ages and don’t provide any support so for the recklessly brave only.)

Controlling Music (iTunes) from a Mac OS Swift app.
 
 
Q