Re: Detecting a new application launch?
Re: Detecting a new application launch?
- Subject: Re: Detecting a new application launch?
- From: JuL <email@hidden>
- Date: Sun, 11 Jan 2004 04:31:50 +0100
Hi,
Perhaps you have to make a timer that regularly checks open
applications using
- (void)check {
int mib[3] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL};
size_t length;
struct kinfo_proc *theProcessInfoData;
struct kinfo_proc *theProcessInfo;
if(sysctl(mib, 3, NULL, &length, NULL, 0) == -1)
return;
theProcessInfoData = (struct kinfo_proc*)malloc(length);
if(sysctl( mib, 3, theProcessInfoData, &length, NULL, 0) != -1) {
theProcessInfo = theProcessInfoData;
do {
NSString * processName = [NSString
stringWithCString:theProcessInfo -> kp_proc.p_comm];
pid_t processID = theProcessInfo -> kp_proc.p_pid;
// Do some checking with the processName and processID
theProcessInfo ++;
} while((size_t)theProcessInfo < (size_t)theProcessInfoData +
length);
}
free((void*)theProcessInfoData);
}
Just compare the current processNames and IDs to the one of the
previous call to get the new app name/ID.
That's a bit heavy but I think it should work..
Regards,
JuL
We've investigated this option and the problem is it doesn't appear to
trigger until the application is done launching, unless there is
something I missed...
On Jan 10, 2004, at 7:09 PM, Chaz McGarvey wrote:
Hey:
On Jan 10, 2004, at 4:24 PM, Colin Cornaby wrote:
I was wondering if there was any sort of notification when a new
application launches. I am interested in keeping track of
application launches in my program and examining the process (so I
need the process id of the launched application) prior to it
completing launch.
Check out NSWorkspace. There is a notification called
NSWorkspaceDidLaunchApplicationNotification. With the notification
comes a dictionary which can be used to look up things about the
application which launched. The @"NSApplicationName" and
@"NSApplicationProcessIdentifier" and should be of interest to you
(read the docs for more info).
One "gotcha." This will only work for applications with a graphical
interface. For example, processes which run in the terminal aren't
dealt with by NSWorkspace. Other than that observation, I'm not sure
what specific qualities define whether a process qualifies to be
picked up by NSWorkspace.
Chaz McGarvey
http://www.brokenzipper.com
-----------------------
Colin Cornaby - Co-Founder, Carpe Stellarem. Duality and XGame
Projects Manager. http://www.carpestellarem.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.