Team LiB   Previous Section   Next Section

Chapter 17. Scripting Sherlock 2

Sherlock 2 is the Apple Computer program that allows you to search the Web or your local file system for any files or web pages that meet the criteria you specify in the search text field. Figure 17-1 shows the Sherlock 2 window. The program is the Find application from pre-Mac OS 8 lineage, but it is significantly renovated for web searching (the second Sherlock version, Sherlock 2, installed with Mac OS 9).

Figure 17-1. Sherlock 2 window
figs/ascr_1701.gif

The software is modeled in part on Internet search-engine methods. For example, Sherlock 2 presents its web search results as a list of hyperlinks ranked by relevance. If you click on the hyperlink, Sherlock 2 opens the default browser and attempts to load the page found by the search. Your machine has to be online, however, for Sherlock 2 to search the Web. For example, if you wanted to find a web page that describes the Berkeley Software Distribution (BSD) commands (so that you can test the use of these commands in Mac OS X's command shell), then initiate these steps with the Sherlock 2 window:

  1. Choose the Internet channel icon (the planet Earth) at the top of the Sherlock 2 window.

  2. Type "BSD commands" in Sherlock 2's search text field.

  3. Click the magnifying glass icon at the right of the text field to start the search.

You can also use Sherlock 2 to initiate finely grained file searches on your local volumes, but only if you have indexed these volumes with Sherlock's indexing feature. Figure 17-2 shows the application's Index Volumes window. Indexing speeds up searching by creating a catalog of important and/or frequently used terms in the document, similar to an index in the back of a book. Indexing a large disk with Sherlock 2 can take an hour or more, but the resultant search speed and results are impressive. You cannot index web sites in this manner, just disks, folders, and files. You can also update or create a new index on folders and files (not just volumes) by selecting the folder or file and choosing Index selection... from the contextual menu. If you want to search just a folder, not any volumes, you can drag the folder into the Sherlock 2 window then initiate a search (as long as the folder was previously indexed).

Figure 17-2. Sherlock 2's Index Volumes window
figs/ascr_1702.gif

Of course, all of these tasks—searching the Web or a giant local hard disk, or indexing files, folders, and volumes—can be accomplished using an AppleScript. To get you started, Example 17-1 tells Sherlock 2 to search the Web for web pages that are relevant to the command "BSD commands." It uses the search Internet command, which has an optional labeled parameter display that specifies whether to show the search results in a Sherlock 2 window:

search Internet for "BSD commands" display true

In this case we want to see the search results. The search Internet command returns a list of URL strings that resulted from the search (see the search Internet command description elsewhere in this chapter).

Example 17-1. Simple Script for Searching with Sherlock 2
tell application "Sherlock 2"

   activate -- make Sherlock the active window

   set query to "BSD commands"

   (* make sure that you catch any network errors and display the error to the user *)

   try

      search Internet for query with display

      on error errmesg

      display dialog errmesg

   end try

end tell
    Team LiB   Previous Section   Next Section