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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to