AppleScript的:获取一个对象或类的所有属性的列表 [英] AppleScript: Getting a list of all properties of an object or class

查看:915
本文介绍了AppleScript的:获取一个对象或类的所有属性的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了存储对象的值对外部(外面)的访问,我需要能够得到那个对象的每个属性,然后我会试着将其转换为文本,并将其存储somehwere。

In order to store an object's values for external (outside AS) access, I need to be able to get every property of that object, and then I'd try to coerce it to text and store it somehwere.

我如何得到一个对象包含的属性列表。作为一个例子,我可以这样写:

How do I get the list of properties that an object holds. As an example, I can write this:

tell me
  get properties
end tell

这对于一个工作的脚本的对象。

That works for a script object.

但是,对于许多其他对象,我只是得到一个错误,如描述符类型不匹配,喜欢这里:

But for many other objects, I simply get an error such as "descripter type mismatch", like here:

tell application "iTunes"
  get properties of file track 1
end tell

现在,我知道优秀的脚本调试器可以做到这一点(它可以显示任何对象的整个一套属性),所以应以书面的AppleScript是可能的。有什么秘诀吗?

Now, I know the excellent Script Debugger can do it (it can show any object's entire set of properties), so it should be possible in written AppleScript as well. What's the secret to this?

推荐答案

标记Alldritt,脚本调试程序的作者,是这么样来解释秘诀给我。

Mark Alldritt, the author of Script Debugger, was so kind to explain the "secret" to me.

脚本调试器使用一些特殊的AppleScript的API函数,包括OSAGetPropertyNames(),以获得这些信息。

Script Debugger uses some special AppleScript API functions, including OSAGetPropertyNames(), to get to this information.

因此​​,如果我在写一个包装,比如C,我也许可以得到这个了。

Hence, if I write a wrapper in, for instance, C, I can probably get to this, too.

结案:)

这篇关于AppleScript的:获取一个对象或类的所有属性的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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