Name

Apple Data Detectors

Dictionary classes

detector instance (from the Apple Data Detectors Scripting osax)

This class represents a record type sent as a parameter to the handle detection routine of your action scripts. The detector instance record has the following properties:

Examples

on handle detection theDetector
   try
      set emailAdd to detected text of theDetector   (* store the detected text in a variable *)
      set theSubject to the text returned of¬
      (display dialog "Please enter the email subject:"¬
      default answer "" buttons {"Okay", "Cancel"}¬ 
            default button 1)
         set theContent to the text returned of¬
         (display dialog "Please¬ 
   enter the message content:" default answer  "" buttons {"Okay", ¬ 
            "Cancel"} default button 1)
      tell application "Outlook Express"
         activate
         make new draft window with properties {subject:theSubject,¬ 
         content:theContent, to recipients:emailAdd} (* make a new 
         email-message window *)
      end tell
      on error errMessage
      display dialog "You could not create a new email message" &¬
      " due to the following  error:" & errMessage
   end try
end handle detection

You have to install any new detectors that you download by using the Apple Data Detectors control panel. Use the File Install Detector File... command from the control panel’s window. Use the File Install Action File... command to install the AppleScripts or actions that you write for Apple Data Detectors. Once installed, the actions are kept in the directory startup disk:System Folder:Apple Data Detectors:Actions.

When you write an ADD action, you have to include certain information in the Script Editor Description field, or the ADD control panel will not install the action. The Description field is a text area at the top of the Script Editor window (Chapter 2 is devoted to Script Editor). This information includes the detector that is used to handle the action, as in Apple::HTTP for the HTTP detector, and the action title that the contextual menu will display. The contextual menu displays when the user Control-clicks some selected text that contains data which ADD looks for, such as a web site address. The next example shows the text that you must add to the Script Editor Description field for a script that opens a web site in Internet Explorer:

(* the first two lines go in the Script Editor Description field *)
Apple::HTTP  -- Name of detector to handle
Get website in IE4.5  -- Contextual menu string
on handle detection decRecord
   set theURL to detected text of decRecord
   tell application "Internet Explorer 4.5"
      Activate
      OpenURL theURL
   end tell
end handle detection

Table 20-1 shows the detector names that scripters use with their action scripts. The first four detector names identify the detectors that are a part of the Internet Address Detectors package; the last two are part of the U.S. Geographic Detectors package.

The AppleScript statements that you include outside of the handle detection subroutine do not run when the action script executes, unless you include them in another routine that handle detection calls. For example, the statement:

display dialog "I am called in handle detection"

executes because it is part of a doDisplay function that is called by handle detection:

On handle detection decRecord
   Set theSel to detected text of decRecord
   Display dialog "here's what you selected: " & theSel¬
   doDisplay(  )
End handle detection

On doDisplay(  )
   display dialog "I am called in handle detection"
End doDisplay