编写 Cocoa 应用程序属性脚本
我的 sdef 字典中有一个名为 busy
的应用程序属性,
<property name="busy" code="mybs" type="boolean" access="r" description="Is application busy?">
<cocoa key="isBusy"/>
</property>
我还有带有 isBusy
访问器的 NSApplication 类别
- (BOOL)isBusy
{
return NO;
}
,脚本
tell application "MyApplication"
properties
end tell
和
tell application "MyApplication"
busy
end tell
工作正常,并且 busy
属性是 false,但脚本
busy of application "MyApplication"
返回错误
error "MyApplication got an error: Can’t make |busy| into type specifier." number -1700 from |busy| to specifier
我的错误在哪里?
I have a property of my application in my sdef dictionary called busy
<property name="busy" code="mybs" type="boolean" access="r" description="Is application busy?">
<cocoa key="isBusy"/>
</property>
Also I have NSApplication category with isBusy
accessor
- (BOOL)isBusy
{
return NO;
}
The scripts
tell application "MyApplication"
properties
end tell
and
tell application "MyApplication"
busy
end tell
work fine and busy
property is false, but script
busy of application "MyApplication"
returns error
error "MyApplication got an error: Can’t make |busy| into type specifier." number -1700 from |busy| to specifier
Where is my mistake?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于
busy
是特定于您的应用程序的术语,因此必须在其前面添加tell
或using terms from
以使该术语在该时刻为人所知。代码。其中任何一个都可以:AppleScript 从左到右解析,并且必须先知道有效术语是什么,然后才能解析它们。它不会跳到
busy of application "MyApplication"
的末尾来弄清楚如何解析表达式的开头。如果 MyApplication 有一个术语busy of
,它将完全改变该表达式的含义并导致悖论:of
将不再是用于构造对象说明符的关键字,这意味着它不会从 MyApplication 获取术语,这意味着它将是of
关键字,并且它会从应用程序获取术语……无穷无尽。您可能想知道为什么某些应用程序属性(例如
name
、version
和running
可以在不引入应用程序术语的情况下工作。它们之所以有效,是因为它们是由全局系统术语定义的,而不是特定于您的应用程序的。请注意,
的
所有格运算符不会引入像tell
那样的术语,因此这也不起作用(除非您在它前面加上告诉
或使用来自
的术语):Since
busy
is a term specific to your application, it must be preceded bytell
orusing terms from
to make the term known at that point in the code. Any of these will work:AppleScript parses left-to-right and has to know what the valid terms are before it can parse them. It doesn’t skip to the end of
busy of application "MyApplication"
to figure out how to parse the start of the expression. If MyApplication had a termbusy of
it would completely change the meaning of that expression and cause a paradox:of
would no longer be the keyword used to construct object specifiers, which means it wouldn’t get terminology from MyApplication, which means it would be theof
keyword and it would get the terminology from the application…ad infinitum.You may be wondering why some application properties, like
name
,version
andrunning
work without introducing the application’s terminology. They work because they’re defined by the global system terminology and are not specific to your application.Note that the
's
possessive operator does not introduce terminology liketell
does, so this doesn’t work, either (unless you precede it with atell
orusing terms from
):这是行不通的,因为这是一个非法的 Apple Script 语句。
regulus6633 建议的
get
命令将在您省略时自动添加到前面(请参阅 Apple 脚本编辑器中的“事件”选项卡)。并且每个命令都需要一个执行者来执行。隐含的get
命令在损坏的句子中没有构建像“blah of blah of blah”这样的说明符所必需的容器This will not work because it is an illegal Apple Script sentence.
The
get
command, which was suggested by regulus6633, will prepended automatically if you omit it (See Events tab in Apple Script Editor). And each command needs a performer to execute it. The impliedget
command has in your broken sentence no container which is necessary to build a specifier like "blah of blah of blah"t