Mac Carbon 应用程序中的可编写脚本 (AppleScript) [英] Scriptability (AppleScript) in a Mac Carbon application

查看:21
本文介绍了Mac Carbon 应用程序中的可编写脚本 (AppleScript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向我的非基于 Cocoa 的应用程序添加 AppleScripting 支持.

我正在使用 AEGetParamDesc 等低级函数,自己处理 form/want/seld 参数.

我的词汇提供了一个类,我们称之为图像".它有一个属性名称".

我得到了一些 Applescript 代码,例如:

获取图片获取每个图像的名称得到计数图像获取每个图像获取第一张图片获取图像 1

因此,基本上,可以访问对象及其属性.

然而,当我尝试这些类似的访问表单时,它们都失败了:

获取名称为foo"的图像

与图像中的 img 重复结束重复

在第一种情况下,看来我必须处理一个 test 表单.

在第二种情况下,计数运算符 (cnte) 不直接请求类对象,而是使用描述索引对象的 cobj 运算符.

这一切都让我想知道这会走多远.我是否必须在我的代码中单独实现 Applescript 的所有可能的语法和运算符?我假设whose"操作符会简单地组合对每个图像"和图像 x 名称"的请求,就像我可以在 Applescript 中单独编写它们一样,而不是对每个请求使用不同的 AppleEvent 公式.

对于来说也是一样.为什么 AppleScript 不简单地执行 name = "foo" 本身的相等性测试,因为它是一个文本比较,根本不应该涉及我的应用程序代码?

有什么我遗漏的吗?我可以将这些转发给我还不知道的 AE 函数,还是我必须自己处理所有可能的比较和流量控制命令?

解决方案

Thomas Tempelmann(因 Find Any File 成名?),如果你真的无法在 Cocoa 中重写应用程序,这里是我多年前写的一篇文章关于 Cocoa 之前的可编写脚本的编码(用 C 语言)的一些细节,包括处理您在上面询问的 formWhose.

http://www.mactech.com/articles/develop/issue_28/路透社.html

这篇文章由 Apple 在其 Develop 杂志上发表,其中包含我为名为Sketch"的示例应用程序编写的源代码.几年前,Apple 发布了自己的示例项目,也称为Sketch".如果对您有帮助,我还有源代码.

祝你好运!

I am trying to add AppleScripting support to my non-Cocoa based application.

I'm working the low level functions such as AEGetParamDesc, handling the form / want / seld parameters myself.

My vocabulary offers a class, let's call it "Image". It has a property "name".

I've gotten some Applescript code working, such as:

get Images
get name of every Image
get count Images
get every Image
get first Image
get Image 1

So, basically, access to both the objects and its properties works.

However, when I tried these similar access forms, they all fail:

get Images whose name = "foo"

and

repeat with img in Images
end repeat

In the first case, it appears I'll have to handle a test form.

In the second case, the count operator (cnte) does not request the class object directly but instead uses a cobj operator describing an index object.

This all makes me wonder how far this will go. Will I have to implement every possible syntax and operator of Applescript individually in my code? I'd assume that the "whose" operator would simply combine the requests for "every Image" and "name of Image x" the way I can indivually write them in Applescript, instead of using different AppleEvent formulas for each of them.

Same for whose <boolean-test>. Why doesn't AppleScript simply perform the equality test of name = "foo" itself, as it's a text comparison which should not have to involve my application code at all?

Is there something I'm missing? Can I forward these to AE functions I'm not yet aware of or do I have to handle every possible comparison and flow control command myself?

解决方案

Thomas Tempelmann (of Find Any File fame?), if you really can't rewrite the app in Cocoa, here is an article I wrote many years ago with some detail about coding (in C) for scriptability pre-Cocoa, including handling formWhose, which you asked about above.

http://www.mactech.com/articles/develop/issue_28/reuter.html

The article was published by Apple in its Develop magazine, and included source code I wrote for a sample application called "Sketch". This was years before Apple released its own sample project also named "Sketch." I still have the source code if it would help you.

Good luck!

这篇关于Mac Carbon 应用程序中的可编写脚本 (AppleScript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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