ScriptingBridge and Catalina/Music.app?

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?

Answered by ibrewster in 400112022

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.

Hi!

Funny: I had the exact problem on the 26th so I didn't see this post.

But I found a solution, at least in my case.. tell me if it works for you too.


Just add in your info.plist a description for the "Privacy - AppleEvents Sending Usage Description" entry.

Unfortunately that didn't seem to do it for me. What do you have in your entitlements file? Maybe I'm missing something there as well...

It's empty...


I suppose that you working with XCode. What happens if you create the .m and .h files alone and compile then using the Terminal?

Oh, so you aren't sandboxing your app? Interesting, though that didn't seem to make a difference when I removed that.


Yeah, I'm working with XCode. Not sure about doing things straight in the terminal - with the frameworks, xib files, etc, I'm not sure of all the arguments I'd need.


That said, maybe it would be worth starting over from scratch. Try the simplest possible sample, and grow it back out from there. See what happens.

Nope. Even a completely brand new project, created just with the Music.h header file, the default .h,/m, and .xib files, three lines of code, a completly empty entitelements file, and that key in the info.plist file and I get the same behavior.


I can't help but feel that one of the many idiodic "security" measures added in Catalina is preventing this from working, but since there are no errors being logged, I can't tell which one, or how to work around it...

Potentially interesting update: Events do seem to be working - that is, when Music changes tracks, for example, my application does get the event correctly, with all the relevant data. So Music.app->My app seems to be working fine, it's only *requesting* data from Music.app that seems to not be working correctly.

Accepted Answer

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.

ScriptingBridge and Catalina/Music.app?
 
 
Q