1

我正在努力使我的应用程序可编写脚本。我与“谁的”过滤子句斗争。

我想让这项工作,但虽然name可以使用,但country不能:

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

sdef 的相关部分如下所示:

<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>

我必须怎么做才能country与“谁的”一起工作?显然,“谁”子句需要一个类型说明符,而不是属性名称,但我无法理解这一点。

我已经实现indicesOfObjectsByEvaluatingObjectSpecifier:了,但这只是被要求name,而不是country

4

1 回答 1

3

哦,我都错了。我的程序代码很好。这个问题是由于我也有一个名为country. 因此,AppleScript 首先查看标识符的最外层范围,然后找到该类 country并尝试将其用于比较。如果错误消息中包含“类”一词,这可能更容易检测到。

现在有两种解决方案:

  1. 重命名 Sdef 中的属性,使其不再与类名冲突,例如改为country name.

  2. 用于of it更改标识符查找的范围,如下所示:

    get every city whose country of it is "Germany"
    

确保如果在多个类中使用相同的属性名称,它们都使用相同的 4 字符类型代码也很重要。否则这个问题也会浮出水面。

于 2016-04-20T22:58:19.800 回答