如何解决术语冲突?

时间:2012-03-29 23:58:01

标签: applescript

Apple Mail为规则条件的account属性定义了类account和常量rule type。 Applescript编译器总是解决术语“帐户”与类的冲突,因此无法对匹配帐户的规则条件执行任何操作。

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

实施例

制定“帐户”规则条件

以下非工作示例的目标是创建一个与帐户匹配的规则条件。

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

比较

以下目标是测试规则条件是否具有规则类型account。对于它,首先在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

我之前的问题“How can I access a property that has the same name as class but different event code?”类似,但仅涵盖类和属性名称之间的冲突。此外,它的解决方案(使用«class ...»)适用于属性,但不适用于其他类型的碰撞。

2 个答案:

答案 0 :(得分:2)

一种解决方法是定义一个帐户类型变量,引用tell application "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

另见Raw code reference,其中显示了«class ...»,«constant ...»和«event ...»原始代码表。

答案 1 :(得分:1)

我已经对你的代码进行了一段时间的实验,但我没有看到任何解决方案 - 这个名称含糊不清似乎是对Apple的疏忽。

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

-- "dummy" was created manually to copy rule types from
set rtype to (rule type of last rule condition of rule "dummy")

set rool to make new rule at end of rules with properties {name:"test", enabled:false}
set rcond to make new rule condition at end of rule conditions of rool with properties {rule type:rtype, expression:"~/Library/Mail/IMAP-john.doe@example.com"}

-- test it:     
properties of rcond