Applications can provide users direct interaction with Spotlight by displaying the standard Finder search interface.
The NSWorkspace
method showSearchResultsForQueryString:
provides a simple interface to the Finder search window. This is the programmatic equivalent of the user switching to Finder, creating a new window, and typing the search string into the search field.
The following code fragment demonstrates extracting a string value from an NSSearchField
and displaying the search interface.
; |
resultCode=[[NSWorkspace sharedWorkspace] showSearchResultsForQueryString:[sender stringValue]]; |
if (resultCode == NO) { |
// failed to open the panel |
// present an error to the user |
} |
Applications prior to Mac OS X v10.6 should continue to use the Carbon's HISearchWindowShow
API.
Last updated: 2010-04-12