Applescript 如何解决术语冲突?

Applescript 如何解决术语冲突?,applescript,Applescript,Apple Mail为规则条件的规则类型属性定义了类帐户和常量帐户。Applescript编译器总是解决术语“account”与类之间的冲突,使得无法使用与accounts匹配的规则条件执行任何操作 当出现这样的冲突时,如何指定常量而不是类名?枚举常量是否有双角度语法?是否有一种解决方案适用于任何类型的术语冲突(不仅仅是类和枚举) 例子 创建“帐户”规则条件 以下非工作示例的目标是创建与帐户匹配的规则条件 tell application "Mail" set rool to make

Apple Mail为规则条件的
规则类型
属性定义了类
帐户
和常量
帐户
。Applescript编译器总是解决术语“account”与类之间的冲突,使得无法使用与accounts匹配的规则条件执行任何操作

当出现这样的冲突时,如何指定常量而不是类名?枚举常量是否有双角度语法?是否有一种解决方案适用于任何类型的术语冲突(不仅仅是类和枚举)

例子 创建“帐户”规则条件 以下非工作示例的目标是创建与帐户匹配的规则条件

tell application "Mail"
    set rool to make new rule at end of rules with properties {name:"test", enabled:false}
    (* the following ends up creating an 'any recipient' condition, as 'account'
       is «class mact»
     *)
    make new rule condition at end of rule conditions of rool with properties {rule type:account, expression:"Some Account"}
    log rule type of last rule condition of rool
    -- result: any recipient

    (* inspecting the event for the following, «class tacc» produces the proper
       record, ({'rtype':'tacc'}), but the rule condition is still an 'any recipient'
     *)
    make new rule condition at end of rule conditions of rool with properties {rule:«class tacc», expression:"Some Account"}
    log rule type of last rule condition of rool
    -- result: any recipient
end tell
比较 下面的目标是测试规则条件是否具有规则类型
帐户
。为此,首先在Mail.app的首选项中创建一个名为“Account”的规则,其中包含一个与某个帐户匹配的条件

tell application "Mail"
    set acctType to rule type of first rule condition of rule "Account"
    log acctType is account
    -- result: false
    log acctType is «class tacc»
    -- result: false
end tell

我前面的问题“”类似,但只涉及类名称和属性名称之间的冲突。此外,它的解决方案(使用«类…»)适用于属性,但不适用于其他类型的冲突。

在对代码进行了一段时间的实验后,我没有看到任何解决方案——这个名称的模糊性似乎是苹果方面的一个疏忽

但是,有一个简单的解决方法:从现有规则复制所需的规则类型(“虚拟”)


对你的代码进行了一段时间的实验,我看不到任何解决方案——这个名字的模糊性似乎是苹果方面的疏忽

但是,有一个简单的解决方法:从现有规则复制所需的规则类型(“虚拟”)


一种解决方法是定义一个帐户类型变量,该变量引用
告诉应用程序“Mail”
块之外的枚举常量:

set theAccountType to «constant eruttacc»
tell application "Mail"
    set rool to make new rule at end of rules with properties {name:"test", enabled:false}
    set theCond to make new rule condition at end of rule conditions of rool with properties {rule type:theAccountType, expression:"Some Account"}
    properties of theCond
end tell

另请参见,其中显示了«类…»、«常数…»和«事件…»原始代码表单。

一个解决方法是在
告诉应用程序“邮件”块之外定义引用枚举常数的帐户类型变量:

set theAccountType to «constant eruttacc»
tell application "Mail"
    set rool to make new rule at end of rules with properties {name:"test", enabled:false}
    set theCond to make new rule condition at end of rule conditions of rool with properties {rule type:theAccountType, expression:"Some Account"}
    properties of theCond
end tell
另请参见,其中显示了«类…»、«常数…»和«事件…»原始代码形式