如何指定同一类的多个AppleScript的子元素? [英] How do you specify multiple AppleScript child elements of the same class?

查看:402
本文介绍了如何指定同一类的多个AppleScript的子元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我加入苹果事件脚本来我的申请。我想能够同时使用下面陈述的在其上

I'm adding Apple Event scripting to my application. I would like to be able to use both of the statements below on it:

-- Every instance of MyObject in the app
every MyObject

-- Only the instances of MyObject the user has selected
selected MyObjects

这是我从相关摘录sdef 文件:

<dictionary>
    <suite ...>
        <class name="application" code="capp" description="Top-level scripting object" plural="applications" inherits="application">
            <cocoa class="MyAppClass" />

            <element type="MyObject" access="r">
                <cocoa key="myobjects" />
            </element>

            <element name="selected MyObjects" code="ABCD" type="MyObject" access="rw">
                <cocoa key="selectedMyObjects" />
            </element>
        </class>

        <class name="MyObject" code="ABcd" inherits="item" plural="MyObjects">
        ...
        </class>
    </suite>
</dictionary>

当我称之为每一个为MyObject ,它返回对象的列表,符合市场预期。但是,当我打电话选择MyObjects ,脚本编辑器中选择MyObjects部分和抱怨:

When I call every MyObject, it returns a list of objects, as expected. But when I call selected MyObjects, the Script Editor selects the "MyObjects" portion and complains:

语法错误

预计行末等,但发现复数类名。

Expected end of line, etc. but found plural class name.

如何能实现我在寻找什么呢?

How can I achieve what I'm looking to do?

推荐答案

您的设计是错误的。请参阅脚本接口指南有点瘦,但好于良好UX做法,什么也没有轮廓。

Your design is wrong. See the Scripting Interface Guidelines for a somewhat thin but better-than-nothing outline of good UX practices.

正确的成语是定义一个属性,通常在应用和/或文件。这可读写或只读,取决于什么是适合你的应用程序。

The correct idiom is to define a selection property, typically on application and/or document. This may be read-write or read-only, depending on what's appropriate to your application.

属性值可以是:


  1. 一个单独的定制对象说明标识所有当前选择的对象,例如的:

  1. A single bespoke object specifier that identifies all of the currently selected objects e.g.:

selection of application "Foo"

selection of document X of application "Foo"

一些更好的基于碳的应用程序和偶尔的可可应用程序都使用这种方法,它允许用户执行强大的查询,如:

Some of the better Carbon-based apps and the occasional Cocoa app use this approach, which allows users to perform powerful queries such as:

get (name of every MyObject of selection of document X)

delete (every job whose status is completed)

但需要您实现更多的工作。

but requires more work for you to implement.

单个对象说明符的列表,每个标识一个选择的项目,例如:

A list of single-object specifiers, each identifying one selected item, e.g.:

{thing B of document X of application "Foo", 
 thing E of document X of application "Foo",...}

这是那么强大,因为用户不能操纵在一个单一的命令中选择的项目而必须遍历列表处理每次打开一个项目之一,但更便宜,为您实现。可可脚本是即使在最好的时候有点瘸,不灵活,和pretty在移动/复制/一次删除多个对象该死无望,这是基于Cocoa的应用程序最常用的方法。

This is less powerful, since users cannot manipulate all of the selected items in a single command but must instead iterate the list processing each item one at a time, but is cheaper for you to implement. Cocoa Scripting being somewhat lame and inflexible even at the best of times, and pretty damn hopeless at moving/duplicating/deleting more than one object at a time, this is the most common approach in Cocoa-based apps.

更新 sdef 这个属性文件:

<property name="selection" code="ABCD">
    <cocoa key="selectedMyObjects" />
    <type type="MyObject" list="yes" />
</property>


对于第一个(好)的设计方法的一个例子,看看脚本编辑器自己的字典。对于第二个示例,请参阅邮件的字典。

For an example of the first (better) design approach, take a look at Script Editor's own dictionary. For an example of the second, see Mail's dictionary.

(提示:要查看脚本编辑器字典,选择文件>打开字典,然后从列表中选择合适的项目要导出字典作为一个SDEF文件,只需确保字典查看器窗口的最前面,然后选择文件>。另存为。)

(Tip: To view a dictionary in Script Editor, choose File>Open Dictionary and select the appropriate item from the list. To export that dictionary as an SDEF file, just make sure the dictionary viewer window is frontmost and choose File>Save As.)

这篇关于如何指定同一类的多个AppleScript的子元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆