Re: Quitting an application
Re: Quitting an application
On Wed, May 08, 2002 at 06:34:28PM -0400, Kent Sutherland wrote:
>
I'm trying to make my application quit System Preferences without having
>
to use too much code, and I haven't seen a Cocoa way of doing it.
>
>
I've tried doing: [NSTask launchedTaskWithLaunchPath:@"/bin/kill"
>
arguments:[NSArray arrayWithObject:@"`ps -auxww | grep System\\
>
Preferences | grep -v grep | grep $LOGNAME | awk '{print $2}'`"]];
>
>
But it hasn't worked, as it sends the whole argument to be killed
>
instead of processing it first. I don't want to have to make a task that
>
runs ps aux and then kills with that returned value, because that's
>
overkill it seems. Is there an easy way to use AppleScripts "do shell
>
script" command in Cocoa easily?
This is really brittle; you shouldn't assume (a) System Preferences is
called 'System Preferences', (b) it's the only program that exists
which contains that anywhere in its name or arguments, or (c)
applications will clean up after themselves if you just kill them.
Instead, use the Carbon Process Manager to find a process whose
creator (signature) matches that of System Preferences. If you'd
rather match on bundle ID, which is the OS X replacement for creator
information, then use GetProcessBundleLocation, make a
NSBundle/CFBundle from it, and get the bundle identifier from there.
Then create a quit Apple Event (either manually or with AEBuild) and
send it. That should do it.
You can also do this from AppleScript by sending events to the 'System
Events' application, to see which processes are running, though I've
found this quite buggy in 10.1.4 and lower, and it'd be more efficient
to use the Process Manager directly anyway.
--
=Nicholas Riley <email@hidden> | <
http://www.uiuc.edu/ph/www/njriley>
Pablo Research Group, Department of Computer Science and
Medical Scholars Program, University of Illinois at Urbana-Champaign
_______________________________________________
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.