Get

The default command is get. In effect, a sentence or clause with no verb is assumed to have get as its verb. So, for example:

tell application "Finder"
    name of folder 1
end tell

The get command is supplied here and is the actual message sent to the Finder. It's exactly as if you had said get explicitly:

tell application "Finder"
    get name of folder 1
end tell

One even sees code written like this:

tell application "Finder" to name of folder 1

AppleScript can also supply get in the middle of a line where needed. As we have already seen, this code:

tell application "Finder"
    set oldname to name of folder 1
end tell

is actually treated by AppleScript as if it said this:

tell application "Finder"
    set oldname to (get name of folder 1)
end tell

Do not imagine, however, that it makes no difference whether you ever say get, and that you can blithely omit it. On the contrary, it's probably better to err in the other direction and say get whenever you mean get. There are no prizes for obfuscated AppleScript, and you're most likely to confuse yourself (and impress no one else) if you get into bad habits. More important, omission of get from expressions of any complexity can cause runtime errors. For example, this:

tell application "Finder" to display dialog (name of folder 1)
-- error: Finder got an error: Can't make name of folder 1 into type string

is not the same as this:

tell application "Finder" to display dialog (get name of folder 1) -- Mannie

In the first example, name of folder 1 is a reference ...

Get AppleScript: The Definitive Guide, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.