Mac OS X Reference Library Apple Developer Connection spyglass button

Displaying the Spotlight Search Window

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: 2009-07-14

Did this document help you? Yes It's good, but... Not helpful...