considering [but ignoring] end [considering]
Use considering
statements to specify the elements that should be considered during
string comparisons and communications with other applications. The
statements that constitute the comparison are enclosed in the
considering...end
considering
block. This statement block affects how each of its enclosed
statements is processed. The considering
statement
can also alter AppleScript’s default behavior for
the code that is executed prior to the end of the
considering
statement (signaled by an
end
or end considering
phrase).
For example, if you wanted to compare two strings and take upper- or
lowercase characters into account, but ignore any white space in the
strings, then you would use the statement: considering case but ignoring white space...end
considering
. AppleScript’s
default behavior is to consider elements such as case, white space,
and punctuation when it compares strings for equality. The following
constants can also be used in the considering statement (Chapter 6
, discusses
AppleScript’s constants):
application responses
case
diacriticals
expansion
hyphens
punctuation
(i.e., . , ? : ; ! \ ' " `)
white space
AppleScript considers by default an application’s
responses to any Apple events that your script sends them. You can
use the ignoring
statement to ignore responses
from an application, as in considering case but ignoring application
responses.
There are a few instances when ignoring application responses might make sense, such as when you are sending quit commands to several running processes. If one of the processes responds to the command with an error, then the script ignores its response (as well as any other application response) and thus prevents it from disrupting the execution of the rest of the script. See “ignoring” in this chapter for more details.
This code shows how to use this statement with a fairly complex string comparison:
tell application "Finder" considering case but ignoring punctuation, white space and hyphens set theTruth to ("voracious appetite" is equal to "voracious,¬ appetite") --returns true end considering end tell
The example tells AppleScript which elements to consider and ignore
when executing the string comparison within the
considering
statement block. Since white space,
hyphens, and punctuation should be ignored in the comparison, the two
strings turn out the same. Therefore, the theTruth
variable is set to true
. If you are wondering why
you would ever ignore these elements in a string comparison, programs
often deal with a lot of junk characters and tokens, such as
markup-language elements, which are returned from applications or web
pages. The considering
statement allows you, in a
minimal way, to filter out elements that you do not want to include
in string comparisons (unfortunately, you will have to write custom
functions or use an HTML-parsing osax to filter out the common <
> characters in hypertext markup language [HTML], as AppleScript
does not consider them to be
“punctuation”).