我有两个字符串属性设置在我的可可应用程序的应用程序委托中,这些属性与KVC兼容。我的.sdef将它们作为文本读写属性公开给applescript。无法通过applescript访问可可属性
当我使用AppleScript的做到以下几点,我的属性被正确返回:
tell application "iKeepFit"
activate
properties
end tell
什么会很奇怪的是,当我尝试访问属性它的名字,applescript编辑器会弹出一个对话框,说我的应用程序有错误。然而,xcode调试输出显示没有消息。以前,当我的.sdef错误时,如果我运行脚本调用我的应用程序时,xcode会显示错误,当它连接到调试器时。
E.g.
propertyname
< - 错误“无法获取属性名称”。编号-1728从«class dact»
set propertyname "value"
< - 错误“无法设置属性名称”。号码-10006从«class dact»
有什么会通常会导致此行为?
我已经浏览了两本可可书,一本苹果手册以及大量示例代码和苹果文档,但它们似乎都以不同的方式实现了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的看法都是不同的,这是关于该语言最令人沮丧的事情之一。 (至少可以说这是一种令人沮丧的语言)我一直希望苹果能够在WWDC上推出一款经过深思熟虑的替代品,即使我知道它的一厢情愿。没有答案你的问题,虽然我同情加入Applescript的挫折。由于脚本功能对高级用户而言无价,苹果真的需要改进这一点。 – Clark 2011-04-25 16:52:25
“我评论了标准套件”对解决我在应用程序中遇到的同样错误非常有用。 – Volomike 2016-04-18 07:01:23