AddThis Social Bookmark Button

Listen Print Discuss

Programming with Spotlight

by Matthew Russell
07/12/2005

The API for Spotlight offers highly advanced search capabilities. In fact, you can develop some of the very features of Tiger we've already grown to love using Spotlight's API. In this piece, we'll ease into Spotlight programming from a Cocoa development perspective so that you can make your applications Spotlight enabled. Next time (this coming Friday), we'll finish our work with Spotlight by hacking up a plugin for Stickies.

Pregame

As with any endeavor, an adequate background is vital to success. Apple has provided quite a bit of documentation on Spotlight, and it is very good, although not quite final. This writing assumes that you've done a bit of Cocoa programming before and understand how Spotlight works at a conceptual level. If you need a quick crash course, review:

We'll ease into the Cocoa programming initially, but will quickly increase the pace because there's a lot of turf to cover with Spotlight specifics. If you need more context on general purpose Cocoa programming than Apple's developer documentation, check out one of the many excellent tutorials here on MacDevCenter. Without further adieu, sit back, relax, and strap on your seat belt.

Developing with Spotlight

Related Reading

Cocoa in a Nutshell
A Desktop Quick Reference
By Michael Beam, James Duncan Davidson

Table of Contents
Index
Sample Chapter

Read Online--Safari Search this book on Safari:
 

Code Fragments only

As a developer, you can interact with Spotlight in a variety of ways. Here are a few of the most common ways:

We'll work though each of these possibilities, and you'll soon be able to interact with Spotlight on a variety of levels. Let's get our hands dirty with some code by building a sample application, looking at some of Apple's examples, and reviewing some of the command line tools.

Displaying the Spotlight Search Window

Since Cocoa is the drink of the day (as always), let's make an example project that interacts with Spotlight. If you haven't already, now is a good time to update to Xcode 2.1. In Xcode:

With a template in place, let's proceed to create a controller class since we're big fans of the Model View Controller paradigm

new project
Create a new project in Xcode

Pages: 1, 2, 3, 4

Next Pagearrow