I'm developing a system that uses an ES extension to control user file openings on Mac.
When a user tries to open a file, the ES extension can either allow or deny the user from opening it. However, the policy for allowing/denying users to open files is managed by my normal Mac app. Therefore, the ES extension needs to proactively communicate with the normal app.
Initially, I wanted to create an XPC service in my regular app, but according to the documentation, XPC services are managed by launchd and cannot be created by regular apps.
So if I want my ES extension to communicate with the regular app proactively, what IPC method can I use?
I attempted creating a local CFMessagePort on the app side, but ES couldn't obtain the remote CFMessagePort. The CFMessagePortCreateRemote always return nil.
Right. This is because they run in different execution contexts. If you’re going to work at this level of macOS, you need to understand how execution contexts work on that system. The best [1] explanation of that is Technote 2083 Daemons and Agents. It’s super old, and a few details have changed over the years, but all the basic ideas are still accurate.
Your sysex runs in the global context. Each instance of your app runs in its own GUI login context. Connecting from your sysex to your app is nonsense because there’s no way to know which instance of your app would receive the connection. Rather, each instance of your app should connect to your sysex.
ES explicitly supports this via the the NSEndpointSecurityMachServiceName
property. See the EndpointSecurity
man page for details.
Note You could use CFMessagePort
for your IPC, but please don’t. Rather use one of our XPC APIs. See XPC Resources for links to documentation and so on.
Keep in mind that your app is not necessarily running. You need to decide what to do if the user quits your app. In many cases the best option is to have a launchd
agent running in each GUI login context. That can, if necessary, interact with the sure, or even launch your app.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] But I’m biased, because I wrote it (-: