Re: problem with NSWorkspace running apps
Re: problem with NSWorkspace running apps
- Subject: Re: problem with NSWorkspace running apps
- From: Ken Thomases <email@hidden>
- Date: Fri, 05 Sep 2014 00:22:45 -0500
On Sep 4, 2014, at 11:25 PM, Jens Alfke <email@hidden> wrote:
> On Sep 4, 2014, at 8:55 PM, Scott Ribe <email@hidden> wrote:
>>
>> It is as though the runningApplications method returns a cached list which is only updated when events are processed, thus I won't see the newly-launched app until the next pass through the runloop, thus cannot launch an app and immediately see it.
>
> I think what's actually going on is that the app doesn't show up as running until it's gotten far enough into its launch process to check in with the WindowServer.
>
> You're dealing with a multi-threaded system, so it makes total sense that an app hasn't shown up a microsecond after you told the system to launch it.
No, it's as he suspected. NSRunningApplication clearly documents that it doesn't update except during a pass through the run loop. Similarly, -[NSWorkspace runningApplications] is clearly documented to have the same property (although I would think NSWorkspace could make an exception for applications that it launches itself).
Scott, as to your question:
> So, is there any way to get an NSRunningApplication instance for an app immediately after launching it, without resorting to some vile nastiness…
-[NSWorkspace launchApplicationAtURL:options:configuration:error:] directly returns the NSRunningApplication that it launched. You can get the URL using -URLForApplicationWithBundleIdentifier: in order to work from a bundle identifier, similarly to -launchAppWithBundleIdentifier:.
If for some reason that's not sufficient, you can try monitoring the NSWorkspaceWillLaunchApplicationNotification notification. I'm not sure if that's synchronous — that it's posted before the -launch… or -open… method returns — but it might be, and it includes an NSRunningApplication in the notification's userInfo dictionary.
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden