1

I am working on making my application scriptable. I struggle with the "whose" filter clause.

I want to make this work, but while name can be used, country can not:

tell application "myapp"
    get every city whose name is "Berlin" -- works
    get every city whose country is "Germany" -- error -1700 (Can’t make country into type specifier)
end tell

The relevant parts of the sdef look like this:

<class name="application" code="capp">
    <cocoa class="NSApplication"/>
    <element type="city">
        <cocoa key="allCities"/>
        <accessor style="index"/>
    </element>
    <class name="city" code="Citi" plural="cities">
        <cocoa class="ScriptableCity"/>
        <property name="name" code="pnam" type="text" access="r">
            <cocoa key="name"/>
        </property>
        <property name="country" code="Ctry" type="text" access="r">
            <cocoa key="country"/>
        </property>
    </class>

What must I do to make country work with "whose" as well? Apparently, the "whose" clause wants a type specifier, not a property name, but I can't make sense of this.

I have implemented indicesOfObjectsByEvaluatingObjectSpecifier:, but that only gets called for name, not for country.

1
  • Consider that you don't have to specify explicitly the cocoa key for a property with the same name. But I recommend to separate always the property of the model from the scripting property by using a category for each cocoa class to avoid terminology clashes. Commented Apr 21, 2016 at 8:03

1 Answer 1

3

Oh, I had it all wrong. My program code is fine. The issue is caused by the fact that I also have a class named country. So AppleScript, looking at the outmost scope for the identifier first, finds the class country and tries to use that for the comparison. Had the error message included the word "class", this would have been easier to detect, probably.

There are now two solutions:

  1. Rename the property in the Sdef so that it does not clash with the class name any more, e.g. to country name.

  2. Use of it in order to change the scope for the lookup of the identifier, like this:

    get every city whose country of it is "Germany"
    

It is also important to make sure that if the same property name is used in several classes, they all use the same 4-char type code. Otherwise this problem can surface as well.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.