Apple Mail defines both a class account and a constant account for the rule type property of a rule condition. The Applescript compiler always resolves this collision of the term “account” to the class, making it impossible to do anything with rule conditions that match accounts.
When there’s a conflict such as this, how can I specify a constant instead of a class name? Is there a double-angle syntax for enumerated constants? Is there a solution that works for collisions of any type of terms (not just classes & enumerations)?
Examples
Making an “Account” Rule Condition
The goal of the following non-working example is to create a rule condition that will match an account.
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
Comparing
The goal of the following is to test whether a rule condition has rule type account. For it, first create a rule in Mail.app’s preferences named “Account” with a single condition that matches some 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
My earlier question “How can I access a property that has the same name as class but different event code?” is similar, but only covers conflicts between class and property names. Moreover, the solution for it (using «class …») works for properties, but not for other types of collisions.
One work-around is to define an account type variable referring to the enumeration constant outside of the
tell application "Mail"block:See also the Raw code reference, which shows the «class …», «constant …» and «event …» raw code forms.