Language Guide
CHAPTER 8
Handlers
Subroutine Definitions and Calls 233
The following subroutine converts inches to centimeters:
on CentimeterConversion from x
--make sure the parameter is a real number or an integer
if class of x is contained by {integer, real}
return x * 2.54
else
error "The parameter must be a real number or an integer"
end if
end CentimeterConversion
--to call CentimeterConversion:
CentimeterConversion of 36
The following subroutine searches for a specific string in a list of files.
to searchFiles of filesToSearch for theString
--filesToSearch: list of Scriptable Text Editor files
--theString: the string to be searched for
set hits to {}
tell application "Scriptable Text Editor"
repeat with i from 1 to (count items of filesToSearch)
set currentFile to item i of filesToSearch
if contents of document currentFile contains theString
--append currentFile to list of hits
set hits to hits & currentFile
end if
end repeat
return hits
end tell
end searchFiles
--to call searchFiles:
searchFiles of {"March Expenses", "April Expenses",
"May Expenses", "June Expenses"} for "LeChateau"
The specified files must be open for the searchFiles handler to work.