Cocoa应用程序中的Applescript [英] Applescript Inside of a Cocoa Application

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

问题描述

对于我写的应用程序,我需要访问一些其他应用程序的项目,为此Applescript似乎是最好的方法。我一直在使用Appscript框架,它工作得很好,因为它允许我线程化它,而不是让我的应用程序锁定时,一个Applescript花了一段时间。但是,现在我试图让我的应用程序64位兼容,并且它似乎像Appscript框架不支持64位。有没有一个好的方式在Cocoa中使用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

推荐答案

看起来像 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事件发送到可编写脚本的应用程序,并接收Apple事件作为响应。从而使得该程序可以控制应用并与其交换数据。脚本桥通过在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包含手动发送和处理Apple事件的方法,但是不应该调用这些方法直。相反,SBApplication的子类实现了应用程序特定的方法来处理自动发送Apple事件。

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轨道,使用iTunes应用程序的动态定义子类的currentTrack方法,它处理为您发送Apple事件的详细信息,而不是找出更复杂,低级的替代方法:

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'];

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

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

希望有所帮助!

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

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