Using Launchd in Mac App Store

I want to create a sanboxed XPC service as a part of my App in the app store.


I want to do that, so that other non-sandboxed command line process (which a power user would download from my web page, not from the app store) would be able to access my service.


The design is:


(UI)--->(XPC service)<----(non-sanboxed command line process)


Such an XPC service can be created with the NSXPCListener initWithMachServiceName:

But how can I add the XPC server configuration to /Library/LaunchDaemon?

I want that the XPC service would be configured automatically when the user installs the app

Is that possible with applications in the Mac App Store? Is there a better way to achieve my design? XPC sees to be what apple recommends?


Thanks

Replies

Is that possible with applications in the Mac App Store?

No. Two things:

  • XPC Services included within an app are only available to that app.

  • Mac App Store apps are not allowed to include a launchd daemon or agent.

There is one thing that will work technically, but I strongly recommend that you not go down this path. As an accident of the implementation, the service registered by a sandbox-compatible login item is visible to other processes running in the user’s session. So on current systems you could make this work by implementing a sandbox-compatible login item (as illustrated by the AppSandboxLoginItemXPCDemo sample code) and have your command-line tools talk to it.

The problem with this approach is that it’s an accident of the implementation rather than a documented feature. Moreover, it runs counter to the general App Sandbox goal that a sandboxed app should be isolated from the rest of the system.

One other option is to have your command-line tools talk to the app via Apple events. That’s fully supported.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks!


1) I'm not familiar with apple events, but my problem with this approach is, it forces the user to launch the app. If the user would do


# myapp status


He'll get no response, if the app isn't launched yet.


Would the Apple Events help me with that? Would Apple Events open my application even if it's closed right now?


2) Another problem I've had is, I preferred interaction with the command line to be headless, i.e., command line would work without showing a new icon on the tray, but if I understand you correctly, there's no supported way to do that. Is that indeed the case?


3) Can you please send me a link about apple events (googling for it gives you mostly the Apple iphone launch events... 😉)

Would Apple Events open my application even if it's closed right now?

Yes.

3) Can you please send me a link about apple events

You should start at the root of the Mac Developer Library and filter (or search) from there.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"