• 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: Close System Preferences programmatically
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Close System Preferences programmatically


  • Subject: Re: Close System Preferences programmatically
  • From: Peter Lübke <email@hidden>
  • Date: Wed, 5 Jan 2011 01:41:16 +0100


Am 04.01.2011 um 23:38 schrieb eveningnick eveningnick:

- If you really want System Preferences to quit, you could use NSAppleScript
and do something like:
tell application "System Preferences" to quit
You can do the same using AppleEvents.

Peter, could you hint me on how to do it using AppleEvents?

Googling, i have found some references to OmniAppKit:
"There's a working example of using Apple Events to do this in the
published Omni frameworks --- let's see, it's OAOpenSystemPreferences
(), in OAPreferenceController.m, in OmniAppKit."

I havent found this kit though, it is quite outdated.



Here are two very simple code samples that terminate an application friendly by sending it an apple event.
They do exactly the same as pressing an app's "Quit" - menu item.
(Use at your own risk!)


// Terminate an application specified by a bundle identifier.
// Returns a BOOL value indicating the success of the operation.
- (BOOL)quitApplicationWithBundleIdentifier:(const char *) bundleIdentifier
{
OSErr err;
AppleEvent quitEvent;

AEInitializeDesc(&quitEvent);

err = AEBuildAppleEvent( kCoreEventClass, kAEQuitApplication,
typeApplicationBundleID, bundleIdentifier, strlen (bundleIdentifier),
kAutoGenerateReturnID, kAnyTransactionID,
&quitEvent, NULL, "from:null()");

if ( err == noErr )
err = AESendMessage(&quitEvent, NULL, kAENoReply, kAEDefaultTimeout);

AEDisposeDesc(&quitEvent);

return ( err == noErr );
}


// Terminate an application specified by a Process Serial Number.
// Returns a BOOL value indicating the success of the operation.
- (BOOL)quitApplicationWithProcessSerialNumber:(ProcessSerialNumber)PSN
{
	OSErr err;
	AppleEvent quitEvent;

	AEInitializeDesc(&quitEvent);

	err = AEBuildAppleEvent( kCoreEventClass, kAEQuitApplication,
									typeProcessSerialNumber, &PSN, sizeof(PSN),
									kAutoGenerateReturnID, kAnyTransactionID,
									&quitEvent, NULL, "from:null()");

	if ( err == noErr )
		err = AESendMessage(&quitEvent, NULL, kAENoReply, kAEDefaultTimeout);

	AEDisposeDesc(&quitEvent);

	return ( err == noErr );
}
_______________________________________________

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


References: 
 >Close System Preferences programmatically (From: eveningnick eveningnick <email@hidden>)
 >Re: Close System Preferences programmatically (From: Nick Zitzmann <email@hidden>)
 >Re: Close System Preferences programmatically (From: eveningnick eveningnick <email@hidden>)
 >Re: Close System Preferences programmatically (From: Peter Lübke <email@hidden>)
 >Re: Close System Preferences programmatically (From: eveningnick eveningnick <email@hidden>)

  • Prev by Date: Re: Close System Preferences programmatically
  • Next by Date: NSBorderlessWindowMask & frontmost behaviour
  • Previous by thread: Re: Close System Preferences programmatically
  • Next by thread: Re: Close System Preferences programmatically
  • Index(es):
    • Date
    • Thread