编写 Cocoa 应用程序属性脚本

发布于 2024-12-18 03:20:12 字数 805 浏览 3 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

行雁书 2024-12-25 03:20:12

由于 busy 是特定于您的应用程序的术语,因此必须在其前面添加 tellusing terms from 以使该术语在该时刻为人所知。代码。其中任何一个都可以:

tell application "MyApplication" to busy

tell application "MyApplication"
  busy
end tell

using terms from application "MyApplication"
  busy of application "MyApplication"
end using terms from

AppleScript 从左到右解析,并且必须先知道有效术语是什么,然后才能解析它们。它不会跳到busy of application "MyApplication" 的末尾来弄清楚如何解析表达式的开头。如果 MyApplication 有一个术语 busy of ,它将完全改变该表达式的含义并导致悖论:of 将不再是用于构造对象说明符的关键字,这意味着它不会从 MyApplication 获取术语,这意味着它of 关键字,并且它会从应用程序获取术语……无穷无尽。

您可能想知道为什么某些应用程序属性(例如 nameversionrunning 可以在不引入应用程序术语的情况下工作。它们之所以有效,是因为它们是由全局系统术语定义的,而不是特定于您的应用程序的。

请注意, 所有格运算符不会引入像 tell 那样的术语,因此这也不起作用(除非您在它前面加上告诉使用来自的术语):

application "MyApplication"'s busy

Since busy is a term specific to your application, it must be preceded by tell or using terms from to make the term known at that point in the code. Any of these will work:

tell application "MyApplication" to busy

tell application "MyApplication"
  busy
end tell

using terms from application "MyApplication"
  busy of application "MyApplication"
end using terms from

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 term busy 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 the of keyword and it would get the terminology from the application…ad infinitum.

You may be wondering why some application properties, like name, version and running 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 like tell does, so this doesn’t work, either (unless you precede it with a tell or using terms from):

application "MyApplication"'s busy
失眠症患者 2024-12-25 03:20:12

这是行不通的,因为这是一个非法的 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 implied get command has in your broken sentence no container which is necessary to build a specifier like "blah of blah of blah"t

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文