Re: AppleEvents from a multiplatform Java app? Working NOW!
Subject : Re: AppleEvents from a multiplatform Java app? Working NOW!
From: Alexander Lohse <email@hidden >
Date: Wed, 29 Sep 2004 11:07:33 +0200
Delivered-to: email@hidden
Delivered-to: email@hidden
Hi,
sorry for my last post I already found the answers.
Here is my code if anyone would like to use it.
I will publish this on out site soon, as I believe this could be of
great public interest.
Maybe some would like to add error-fetching capabilities from the
NSMutableDictionary?
________________________________________________________________________
__________
package de.webjazz.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.io.File;
public class AppleScriptTest {
private Log _log = LogFactory.getLog(this.getClass());
public AppleScriptTest() {
StringBuffer sb = new StringBuffer();
sb.append("tell application \"MacGiro\" \n");
sb.append(" activate \n");
sb.append("end tell");
try {
URL url = new File("/System/Library/Java").toURL();
ClassLoader cl = new URLClassLoader(new URL[]{url});
Class nsappClass =
Class.forName("com.apple.cocoa.application.NSApplication", true, cl);
Method methsharedApp =
nsappClass.getMethod("sharedApplication", null);
methsharedApp.invoke(null,null);
Class nsscriptClass =
Class.forName("com.apple.cocoa.foundation.NSAppleScript", true, cl);
Class nsdictClass =
Class.forName("com.apple.cocoa.foundation.NSMutableDictionary", true,
cl);
Class parts[] = new Class[1];
parts[0] = String.class;
Object args[] = {sb.toString()};
Constructor scriptConst =
nsscriptClass.getConstructor(parts);
Constructor dictConst = nsdictClass.getConstructor(null);
Object nsScriptObject = scriptConst.newInstance(args);
Object nsdictObject = dictConst.newInstance(null);
Method methExecute = nsscriptClass.getMethod("execute", new
Class[] {nsdictClass});
methExecute.invoke(nsScriptObject, new Object[]
{nsdictObject});
} catch (Exception exc) {
_log.debug(exc.getMessage(), exc);
}
}
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden
This email sent to email@hidden
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.