I have an application I wrote a while ago that uses the ScriptingBridge framework to interact with iTunes, both getting information from iTunes (such as the current player position or track lyrics) as well as controlling iTunes (such as play/pause or previous/next track). With the update to Mac OS X Catlina, and the replacement of iTunes with Music.app, this obviously stopped working. I was hoping updating it would be a simple matter of replacing references to iTunes with references to Music, and inital indications were good: a quick look at the Music.app scripting dictionary revealed many, if not all the same script commands being available, and switching out the app identifiers in my code (and the entitlements file) enabled a succesfull build.
Unfortunately, when I ran it, nothing worked. I didn't get any errors - either in the application run log or the system console (for example, I didn't see any sandbox errors indicating that I messed up the entitlements) - but nothing functioned. Digging deeper, I discovered that every command I tried to send to the SBApplication instance returned "nil", or in some cases, a default value such as 0. From what I can tell, however, the SBApplication was initalized correctly. The code I used for initalization is this:
Music=[[SBApplication applicationWithBundleIdentifier:@"com.apple.Music"] retain];
(Where Music is a MusicApplication * defined on the @interface), and if I do a "po Music" in the debugger prompt I get this:
<SBScriptableApplication @0x600000c88810: application "Music" (33039)>
Which seems to indicate it is initialized. So that's good. However, if I do, for example, a "po [Music version]" from the debugger, I get nil. "po [Music playpause]" simularly returns nil, which might be correct in that case, but Music.app does NOT play or pause. playerPosition always returns 0. On the other hand, more fundamental commands, like isRunning, quit, and run, do seem to work, indicating that at some level things are working and I do have the correct linkages set up. So what am I missing? What do I need to change to get the app working with Music.app rather than iTunes?
Got it. Under the target settings, Signing & Capabilities tab, at the end of the "hardened Runtime" section, there is now a checkbox for "Apple Events". This needed to be checked in addition to the other entries in the entitlements file in order to get things working again. Once I checked that box, and confirmed that yes, I really do want my app to do what I told it to do, it started working properly again.