me
me
is used to specify a script-defined subroutine
or property, to distinguish it from the properties or functions of
other applications that the script uses. me
is
most often used in the form
propertyname
orfunctionname
of me.
In the following code, the
me
predefined variable is used inside a
tell...end tell
statement block to identify the
getMegabytes function as a script subroutine,
not a Finder command. If you left out the of me
part of getMegabytes(b) of me then the script
would raise an error, because it would tell the Finder to call its
getMegabytes handler, but the Finder
doesn’t define this command. In the absence of the
me
or my
constants, all
commands inside of a tell...end tell
block are
directed to the application targeted by the tell
block or to scripting additions (Chapter 7discusses
tell
blocks). The script identifies
getMegabytes as its own subroutine, which is an
elegant way to call this useful routine anywhere you want in the
script:
tell application "Finder" set b to largest free block -- returns free memory block as bytes set mb to getMegabytes(b) of me display dialog mb end tell (* subroutine definition; converts bytes to megabytes *) on getMegabytes(byteVal) if (class of byteVal) is in {integer, real} then set megValue to (byteVal / 1024 / 1024) return megValue else return 0 end if end getMegabytes