Cocoa应用程序的AppleScript的内幕 [英] Applescript Inside of a Cocoa Application

查看:183
本文介绍了Cocoa应用程序的AppleScript的内幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关我写的应用程序,我需要访问一些其他应用程序的项目,为此,AppleScript的,似乎最好的一段路要走。我一直在使用Appscript框架,运作良好,因为它让我拧它,而不是让我的应用程序锁定,当一个AppleScript正在采取一段时间。不过,现在我试图让我的应用程序的64位兼容的,它好像Appscript框架不支持64位。有没有一个好的方式来使用AppleScript的可可,不会锁住我的应用程序,但还是给了我完全控制我需要什么?

For the application I am writing, I need to access some other applications' items, for which Applescript seems the best way to go. I have been using the Appscript framework, which worked well, because it allowed me to thread it and not make my app lock up when an Applescript was taking a while. However, now I am attempting to make my application 64 bit compatible, and it seems like the Appscript framework does not support 64 bit. Is there a "good" way to use Applescript in Cocoa that will not lock up my application, but still give me the full control I need?

- firen

--firen

推荐答案

这似乎是<一个href=\"http://developer.apple.com/documentation/Cocoa/Reference/SBApplication%5FClass/SBApplication/SBApplication.html\"><$c$c>SBApplication应该工作,但我还没有使用过。

It seems like SBApplication should work, but I haven't used it before.

根据 @cocoadevcentral

SBApplication:用来进行跨应用脚本使用Objective-C,而不是AppleScript的电话。例:获取当前的iTunes曲目

SBApplication: use to make cross-application scripting calls with Objective-C instead of AppleScript. Ex: get current iTunes track.

下面是从文档的节选:

该SBApplication类提供了一个机制,使一个Objective-C程序发送苹果事件脚本化的应用程序和接收苹果事件的反应。因此,它能够为程序与它控制应用程序和数据交换。脚本桥接工作方式是Apple事件描述符和Cocoa对象之间的桥接数据类型。

The SBApplication class provides a mechanism enabling an Objective-C program to send Apple events to a scriptable application and receive Apple events in response. It thereby makes it possible for that program to control the application and exchange data with it. Scripting Bridge works by bridging data types between Apple event descriptors and Cocoa objects.

虽然SBApplication包括手动发送和处理苹果事件的方法,你不应该直接调用这些方法。相反,SBApplication的子类实现应用程序特定的方法来处理苹果公司发生的自动发送。

Although SBApplication includes methods that manually send and process Apple events, you should never have to call these methods directly. Instead, subclasses of SBApplication implement application-specific methods that handle the sending of Apple events automatically.

例如,如果你想获得当前的iTunes曲目,你可以简单地使用动态定义的子类的currentTrack方法的iTunes应用程序,用来处理发送的苹果事件中,你,而不是搞清楚的细节更复杂的,低水平的替代:

For example, if you wanted to get the current iTunes track, you can simply use the currentTrack method of the dynamically defined subclass for the iTunes application—which handles the details of sending the Apple event for you—rather than figuring out the more complicated, low-level alternative:

[iTunes propertyWithCode:'pTrk'];

如果您确实需要手动发送苹果事件,请考虑使用NSAppleEventDescriptor类。

If you do need to send Apple events manually, consider using the NSAppleEventDescriptor class.

希望帮助!

这篇关于Cocoa应用程序的AppleScript的内幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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