Running my application on event: another application's start
Hello! I am no sure if it is a right list to post this message. Sorry if not :) How could i implement the subj? What i need to do - is to launch a "plugin process" (ordinary cocoa application, written by me) when the host application (ordinary carbon application, Microsoft Word) starts, i.e. when the user launches it from the dock, or doubleclicks on any *.docx icon in finder. On other lists I've been told to use launchd, but it turns out that Launchd doesn't support events like watching another application start, so i am curious if someone has implemented something similar, and how can it be implemented. "Who" in OS X can give me a notice, that a new process with name "Microsoft Word" has been launched? So far i see the solution like an agent, that is started with the system start, and which somehow pulls "ps" command in forevercycle, watching for "Microsoft Word" to appear in the list. If it word is started - this agent starts my plugin. If not - it continues pulling "ps". Maybe there's more sane way to perform that, something more "neat" and something that wouldn't irritate user. Thanks a lot for any advice George
On 3 Oct 2010, at 15:14, eveningnick eveningnick wrote:
"Who" in OS X can give me a notice, that a new process with name "Microsoft Word" has been launched?
There's no way you can achieve your goal directly; you will have to run all the time and watch for the app being launched. However, there are easy ways to achieve both of those steps: o As long as your running in the same GUI login context as the target application, you can hear about its launch via NSWorkspace (specifically NSWorkspaceDidLaunchApplicationNotification). On older systems you can use Carbon Events (kEventAppLaunched) to achieve the same results. o The best way to ensure that you're running in the correct context is to install yourself as a GUI launchd agent. See Technote 2083 "Daemons and Agents" for background information about the above. <http://developer.apple.com/mac/library/technotes/tn2005/tn2083.html> S+E -- Quinn "The Eskimo!" <http://www.apple.com/developer/> Apple Developer Relations, Developer Technical Support, Core OS/Hardware
participants (2)
-
eveningnick eveningnick
-
Quinn "The Eskimo!"