我怎样才能访问具有相同名称的类,但不同的事件code的属性? [英] How can I access a property that has the same name as class but different event code?

查看:103
本文介绍了我怎样才能访问具有相同名称的类,但不同的事件code的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当应用程序使用同一个名字的一类和属性,但不同的事件codeS,我尝试使用属性中的对象说明,AppleScript的跨$ P $点标识符作为类,而不是属性。例如:

When an application uses the same name for a class and a property but different event codes, and I try to use the property in an object specifier, AppleScript interprets the identifier as the class rather than the property. For example:

tell application "Mail"
    header of first rule condition of first rule
end

这导致错误:

邮件得到了一个错误:无法获取的规则1的规则条件1头

Mail got an error: Can’t get header of rule condition 1 of rule 1.

中的AppleScript编辑器标题(蓝色斜体)的样式表明它是一个类名,而不是一个属性。我怎么可以指定标识是一个属性,并明确解决这个命名冲突?

The styling of header in AppleScript Editor (blue italics) suggests it's a class name rather than a property. How can I specify the identifier is a property and resolve this naming collision explicitly?

我运行OS X 10.6.8和Mail.app 4.5。

I'm running OS X 10.6.8 and Mail.app 4.5.

AppleScript的:权威指南,马特·纽伯格认为,及其可用于:

In "Applescript: The Definitive Guide", Matt Neuberg suggests that its may be used:

关键字当应用程序定义的属性具有相同的名称作为类是必要的。 [...]话说及其 disambiguates。

The keyword it is needed when an application has defined a property with the same name as a class. [...] Saying its disambiguates.

不过,这并没有解决问题,我的样本code以上。添加后及其仍样式为一类,并在同一个错误的脚本结果。

However, this doesn't resolve the issue in my sample code above. After adding its, header is still styled as a class and the script results in the same error.

tell application "Mail"
    its header of first rule condition of first rule
end

这§20.8.3应用的例子。 与同名类属性具有相同的效果。

Applying the example from § 20.8.3. "Properties with Eponymous Classes" has the same result.

tell application "Mail"
    tell first rule
        tell first rule condition
            get its header
        end tell
    end tell
end tell

背景

我试图写一个AppleScript扩展Mail.app的规则条件,支持模式匹配。在这些扩展规则之一,有些规则条件是包含脚本的信息,如模式来匹配,如果匹配的模式,而不是条件的邮件应匹配采取行动。我想利用属性这些规则条件。

替代延长规则,以允许模式匹配方式是罚款,但没有要求。我还是想对特定问题的回答,因为这个问题能比这个特定使用其他情况下出现的。

Alternative ways of extending rules to allow for pattern matching are fine but not requested. I'd still like the particular question answered, since the issue can arise in cases other than this particular usage.

推荐答案

编辑:我能得到它,你做一些清理描述失败。脚本编辑器似乎在锁定到任何其第一个猜测是,这样一个解决办法是使用运行脚本以使用原始类在运行时,例如:

I was able to get it to fail as you described by doing some rearranging. The Script Editor does seem to lock in to whatever its first guess was, so one solution would be to use run script to use the raw class at run time, for example:

tell application "Mail"
    header of (get properties of first rule condition of first rule) -- fails
end tell

set myHeader to (run script "tell application \"Mail\"
    return «class rhed» of (get properties of first rule condition of first rule)
end tell")
myHeader --> success

这篇关于我怎样才能访问具有相同名称的类,但不同的事件code的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆