无法通过 applescript 访问 cocoa 属性
我在可可应用程序的应用程序委托中设置了两个符合 KVC 的字符串属性。我的 .sdef 将它们作为文本读写属性公开给 applescript。
当我使用 applescript 执行以下操作时,我的属性会正确返回:
告诉应用程序“iKeepFit”
激活
属性
end Tell
奇怪的是,当我尝试通过名称访问该属性时,applescript 编辑器会弹出一个对话框,提示我的应用程序出现错误。然而 xcode 调试输出没有显示任何消息。以前,当我的 .sdef 错误时,如果我在附加到调试器时运行调用我的应用程序的脚本,那么 xcode 会显示错误。
例如propertyname
<- 错误“无法获取 propertyname。”来自 «class dact» 的编号 -1728set propertyname "value"
<- 错误“无法设置 propertyname。”来自“class dact”的数字-10006
有什么东西通常会导致这种行为吗?
我已经阅读了两本 cocoa 书籍、一本 applescript 书籍以及大量示例代码和 Apple 文档,但它们似乎都以不同的方式实现 applescript 支持。到目前为止,我得到的是最接近工作代码的尝试全部。这是我的 .sdef 文件:
<!-- 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名称。
请帮忙。谢谢。
I have two string properties setup in my cocoa application's app delegate which are KVC compliant. My .sdef exposes them to applescript as text read-write properties.
When I use applescript to do the following, my properties are returned correctly:
tell application "iKeepFit"
activate
properties
end tell
What gets weird is that when I try to access the property by its name, applescript editor will popup a dialog saying my app had an error. Yet xcode debug output shows no messages. Previously when my .sdef was wrong then xcode would show errors if I ran the script calling my app when it is attached to the debugger.
E.g.propertyname
<- error "Can’t get propertyname." number -1728 from «class dact»set propertyname "value"
<- error "Can’t set propertyname." number -10006 from «class dact»
Is there something that would typically cause this behavior?
I've gone through two cocoa books, an applescript book and lots of sample code and apple documentation, but they seem to all implement applescript support differently. What I've got so far is the closest to working code from trying them all out. Here's my .sdef file:
<!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>
I commented out the standard suite stuff because surprisingly it's broken and produces the following error: .sdef warning for argument 'FileType' of command 'save' in suite 'Standard Suite': 'saveable file format' is not a valid type name.
Please help. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决方案。在 Snow Leopard 中,Applescript 显然不知道应用程序中定义了哪些属性,除非它被
using terms from
块包围。由于某种原因,元素中需要一个 id="blah" 属性 - 我发现的唯一原因是通过查看
.sdef
编辑程序的输出。真正令人沮丧的是,这不在我读过的任何示例或文档中。I was able to find a solution. In Snow Leopard, Applescript apparently doesn't know what properties are defined in the application unless it's surrounded by a
using terms from
block.And for some reason the <class> element needed an id="blah" attribute in it - the only reason I've found that is by looking at the output of an
.sdef
editing program. The real frustrating part is that this isn't in any of the examples or documents I've read.