Nonsensical Apple Events
As we saw in a previous section ("Compile-time Error"), AppleScript will sometimes blow the whistle at compile time to indicate that you are using a term as the wrong "part of speech." This is extremely helpful. For example, you can't use a verb as a noun:
tell application "Finder"
get name of eject -- compile-time error: Expected expression but found command name
end tellAnd you can't assign to a class:
tell application "Finder"
set container to "howdy"
-- compile-time error: Can't set «class ctnr» to "howdy". Access not allowed
end tellYou have to supply valid parameter names:
tell application "Finder"
duplicate x by y -- compile-time error: Expected end of line but found "by"
end tellThe duplicate command doesn't have a by parameter, and the compiler knows this.
You can't make an element specifier out of something that isn't a class name:
tell application "Finder"
get name 1 -- compile-time error: Expected end of line but found number
end tellThe compiler also displays some intelligence about singular and plural forms of a class name. The plural form of a class name is taken to be a synonym for the every element specifier; otherwise, if you use a plural where a singular is expected or vice versa, the compiler will usually change it for you, silently:
tell application "Finder"
folder -- folder (the class name)
folders -- {...}, a list of references to every folder
folders 1 -- compiles as folder 1
folder 1 thru 2 -- compiles as folders 1 thru 2
end tellThis ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access