转自:http://cocoatutorial.grapewave.com/2010/01/opening-system-preferences-pane/
Hi All,
In this post, we are going to look at how to programatically open a Preference Pane in the Mac OS X. It is really simple and there are no special requirements to it. In the previous post, we saw how to retrieve the focused window using the Accessibility APIs. In this post, we are going to add on to it by opening the Universal Access Preference pane if the user does not have assistive devices enabled.
Since all the preferences are stored in file with a .prefPane extension, all we basically have to do it is
//opening the Universal Access Preference Pane.
[[NSWorkspace sharedWorkspace] openFile:@"/System/Library/PreferencePanes/UniversalAccessPref.prefPane"];
The list of Preference Pane are the .prefPane files in the folder /System/Library/PreferencePanes/. Adding on to the previous post, we would open the Preferences if the Accessibility API is not enabled.
if(!AXAPIEnabled()){
[[NSWorkspace sharedWorkspace] openFile:@"/System/Library/PreferencePanes/UniversalAccessPref.prefPane"];
[NSApp terminate:self];
}
AXUIElementRef _systemWideElement;
AXUIElementRef _focusedApp;
CFTypeRef _focusedWindow;
_systemWideElement = AXUIElementCreateSystemWide();
AXUIElementCopyAttributeValue(_systemWideElement,
(CFStringRef)kAXFocusedApplicationAttribute,(CFTypeRef*)&_focusedApp);
AXUIElementCopyAttributeValue((AXUIElementRef)_focusedApp,
(CFStringRef)NSAccessibilityFocusedWindowAttribute,(CFTypeRef*)&_focusedWindow)