[launchd-dev] Creating a Launch Agent (per user) on demand when client app is open
dsorresso at apple.com
Thu Jan 15 08:56:29 PST 2015
This sounds like a good use case for an XPC service. The service would ship in your app's bundle, and each instance of your app would have a private instance of the service that it talked to, and that instance would run with the same uid as your app. More here:
On 15 Jan, 2015, at 04:25, Piotr Panasewicz <piotr.panasewicz at mac.com> wrote:
> I would like to create a Launch Agent that would start on demand when my bundle app requires it. I have it currently implemented like below which monitors a specific path for existence of a file. This works ok for one user logged in. If I there are more users logged via Fast User Switching the OS tends to open the service for different user, not the one that’s currently using my app. That’s because two users are now monitoring the same path and the OS isn’t sure in which user’s context the service should run.
> Also my bundle app has LSMultipleInstancesProhibited set to true, so it isn’t allowed to run two instances at once. But if User A opens my app and there is a User B logged in, the service may open for User B (even the file from the plist was created by User A and User B hasn’t touched my app).
> Therefore I need a solution that would allow my client app to open the service for the same user it runs as. And if I close the app for User A, switch to User B and start the client, the service would now open for User B.
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
> <plist version="1.0">
> launchd-dev mailing list
> launchd-dev at lists.macosforge.org
More information about the launchd-dev