• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Quitting an application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Quitting an application


  • Subject: Re: Quitting an application
  • From: Nicholas Riley <email@hidden>
  • Date: Wed, 8 May 2002 22:48:03 -0500
  • Mail-followup-to: Kent Sutherland <email@hidden>, email@hidden

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.

References: 
 >Quitting an application (From: Kent Sutherland <email@hidden>)

  • Prev by Date: OmniExpat?
  • Next by Date: DO and Proxy Indirection
  • Previous by thread: Re: Quitting an application
  • Next by thread: Drawing on the back of an NSWindow
  • Index(es):
    • Date
    • Thread