Name

Sherlock 2

Synopsis

The following sections describe the commands and classes included with the Sherlock 2 dictionary. Chapter 2 , describes application dictionaries if you are not familiar with them.

Dictionary commands

count reference to object

This command counts the number of objects that are specified in its parameter:

tell app "Sherlock 2" to count channels

If you added the code count result to the end of Example 17-1 (just before end tell), then this code would return the number of web sites that the search returned. The return value is an integer.

exists reference to object

If your Sherlock 2 script is running on a different machine than your own, you will have to find out whether a certain channel exists before you specify it in a scripted search. The following example initiates a search only if the “Apple” channel exists on the machine running the script. This command returns a boolean value, true or false:

tell application "Sherlock 2"
   if exists channel "Apple" then
      activate
      (* make sure that you catch any network errors and display the error to the user *)
      try
         search Internet in channel "Apple" for "Mac OS X" with¬
         display
         on error errmesg
         display dialog errmesg
      end try
   else
      display dialog "The Apple channel is not installed."
   end if
end tell
get reference to object

This is the common AppleScript get command, which can be omitted in most cases when you are getting references to Sherlock objects. For example, you can use the code:

tell app "Sherlock 2" to channels

Get AppleScript in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.