DekGenius.com
[ Team LiB ] Previous Section Next Section

10.3 Get

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

tell application "Finder"
        name of folder 1
end tell

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

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 get for the rest of your life. 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

is not the same as this:

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

In the first example, name of folder 1 is a reference to a property; that's not something that can be displayed by display dialog, so we get an error. In the second, the get command fetches the value of that property, a string, and all is well.

    [ Team LiB ] Previous Section Next Section