AppleScript tell command issue

I’m a bit baffled by the tell statement. While its very easy to simply write `tell application “Xcode”` all the time and just get on with life, I’m not so inclined. I want to learn and use AppleScript's object-oriented type system. The documentation for the tell command clearly states the syntax as:

tell referenceToObject      [ statement ]...  end [ tell ]

Where referenceToObject is defined as

referenceToObject Any object. Typically an object specifier or a reference object (which contains an object specifier).

I have two different attempts at this one line of code. The first one is using the "application “Name”" method, the second is more indirect. And even though I’ve also tried setting the xcode property to a reference to the application specifier, the code still won’t compile.


Direct: all is calm, all is bright :-)

on direct()
  tell application "Xcode"
    get the name of the active run destination of the active workspace document
  end tell
end direct


Indirect: armageddon

property xcode : application "Xcode"
on indirect()
  tell xcode
     get the name of the active run destination of the active workspace document
  end tell
end indirect


When compiling, it highlights the word “destination” and displays the following error reason:

Expected “given”, “with”, “without”, other parameter name, etc. but found identifier.


Note: “active run destination” is a property on a “workspace document” class, of which “active workspace document” is a property on the Xcode application object.


Even with xcode defined as `property xcode : a reference to application "Xcode”` it still gives the same error message.


Why does the second approach not work, when the documentation says it should work with a reference or a specifier? Is something wrong with my `tell xcode` clause? How do I get the second approach to work?

Replies

The Script Editor is highlighting the term because it doesn't know what it is, so it is making a guess that it is a handler parameter. An object specifier is normally fully resolved only when a script is run, but for the tell statement the Script Editor needs to know exactly what the application is in order to load its terminology at compile time. The specifier in this case needs to be an absolute object specifier instead of something ambiguous such as a property or variable.

Thanks for the explanation. That makes a lot of sense. It's quite an unusual language.

Someone has clued me up about

use Xcode : application "Xcode"

that loads the terminology for access throughout the entire script which allows me to do what I want.

Oooh - I'm keeping that one too.