0

I want to have my Java swing application be applescriptable.

I am not trying to just respond to pre-defined events like open, print, etc.

It would be best if the AppleEvents appeared through a Listener interface.

Edit: A little bit of explanation of my understanding of Apple Events may help demonstrate that I'm not a slacker. :-) I've written code here that demonstrates how to respond to a lot of the pre-defined events:

https://github.com/joelkevinjones/snippets/blob/e7b10128156bcc213f8c24dbda464ad09a8a1e33/Java/AppleSpecific/AppleLookAndFeelDemo.java

Apple Events are delivered to regular applications using a non-Java interface. There are no supplied Java methods for obtaining these events, so far as I've been able to discover. The Apple Event technology includes writing "terminology" files which describe in human readable form what events an application responds to and the four-letter codes for building up Apple Events programatically. Creating an instance of javax.script.ScriptEngine doesn't do what I want. It allows a Java program to initiate calling AppleScript, but no means for having AppleScript call a Java program.

To clarify, are there are already written libraries or examples that show how to:

  1. Mark or register certain Java methods as being "visible" as AppleScript methods and/or classes as AppleScript classes.

  2. Failing a declarative approach, is there a Java method for capturing Apple Events sent to the Java application? If the event just gets returned as an array of bytes, then the event can be parsed and turned into a Swing event and the reverse process can be used to return results to the application that sent the Apple Event.

  3. Or does lots of JNI code need to written?

4

1 回答 1

0

实现 com.apple.eawt 包中可用的 Application 和 ApplicationAdaptor 类。通过在 ApplicationAdaptor 类中实现事件处理程序,您的应用程序可以生成和处理基本事件,例如打印和打开。J2SE 5.0 Apple Extensions Reference 中提供了有关这两个类的信息。

Java SE 6 还允许您使用 javax.script API 调用 AppleScript。下面的清单提供了此功能的示例实现。

public static void main(String[] args) throws Throwable {
    String script = "say \"Hello from Java\"";

    ScriptEngineManager mgr = new ScriptEngineManager();
    ScriptEngine engine = mgr.getEngineByName("AppleScript");
    engine.eval(script);
}

来源:http: //qery.us/3xr

于 2013-07-18T08:39:34.090 回答