【发布时间】:2011-04-24 02:18:36
【问题描述】:
我在可可应用程序的应用程序委托中设置了两个符合 KVC 的字符串属性。我的 .sdef 将它们作为文本读写属性公开给 applescript。
当我使用 applescript 执行以下操作时,我的属性会正确返回:
tell application "iKeepFit"activatepropertiesend tell
奇怪的是,当我尝试按名称访问属性时,applescript 编辑器会弹出一个对话框,提示我的应用程序出错。然而 xcode 调试输出没有显示任何消息。以前,当我的 .sdef 错误时,如果我在附加到调试器时运行调用我的应用程序的脚本,xcode 会显示错误。
例如propertyname set propertyname "value"
有什么东西通常会导致这种行为吗?
我已经阅读了两本可可书、一本 AppleScript 书籍以及大量示例代码和 Apple 文档,但它们似乎都以不同的方式实现了 AppleScript 支持。到目前为止,我所得到的是最接近工作代码的全部尝试。这是我的 .sdef 文件:
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<!-- use XInclude to include the standard suite
<xi:include href="file:///System/Library/ScriptingDefinitions/CocoaStandard.sdef" xpointer="xpointer(/dictionary/suite)"/>
-->
<suite name="iKeepFit Scripting" code="iKft"
description="Commands and classes for iKeepFit Scripting">
<class name="application" code="capp" description="The application class.">
<!-- the following names the Objective-C class where Cocoa will look for
the property accessor methods for the properties we define for
this AppleScript class. -->
<cocoa class="MyApplication"/>
<!-- the 'done' property. -->
<property name="completedactivity" code="dAct" description="An activity that was completed" type="text" access="rw">
<cocoa key="doneActivity"/>
</property>
<!-- the 'cancel' property. -->
<property name="canceledactivity" code="cAct" description="An activity that was canceled" type="text" access="rw">
<cocoa key="cancelActivity"/>
</property>
<responds-to name="completed">
<cocoa method="handleCompletedActivityScriptCommand:"/>
</responds-to>
</class>
</suite>
我注释掉了标准套件的内容,因为令人惊讶的是它已损坏并产生以下错误:.sdef warning for argument 'FileType' of command 'save' in suite 'Standard Suite': 'saveable file format' is not a valid type name.
请帮忙。谢谢。
【问题讨论】:
-
你注意到每个人都以不同的方式实现 Applescript 是该语言最令人沮丧的事情之一。 (至少可以说这是一种令人沮丧的语言)我一直希望 Apple 能够在 WWDC 上推出一个经过深思熟虑的替代品,尽管我知道它的一厢情愿。没有回答您的问题,尽管我对添加 Applescript 的挫败感表示同情。 Apple 确实需要改进这一点,因为脚本能力对于高级用户来说非常宝贵。
-
“我注释掉了标准套件”对于解决我在应用程序中遇到的相同错误非常有用。
标签: cocoa properties applescript osx-snow-leopard