J
Jon Fogh
Hi I am experimenting with calling apple scripts from Java. I am using
the com.apple.cocoa classes.
I have this small Java program:
public class Test {
public static void main(String[] args) {
NSApplication.sharedApplication();
NSMutableDictionary error = new NSMutableDictionary();
String source = "";
source += "on run (mystr)\n";
source += "tell application \"Finder\"\n";
source += "display dialog \"Got a string: \" & mystr\n";
source += "end tell\n";
source += "end run\n";
NSAppleScript script = new NSAppleScript(source);
script.compile(error);
System.out.println("Error: " + error);
System.out.println("Is compiled: " + script.isCompiled());
NSAppleEventDescriptor desc =
NSAppleEventDescriptor.listDescriptor();
desc.insertDescriptor(NSAppleEventDescriptor.descriptorWithString("Hello
World"),0);
System.out.println("Desc: " + desc.stringValue());
script.executeAppleEvent(desc, error);
System.out.println("Error: " + error);
}
When running it, i get this:
Error: {}
Is compiled: true
Desc: Hello World
Error: {NSAppleScriptErrorNumber = -50; }
The ErrorNumber -50, indicates an error in the user parameter list. I
am not sure this i the right way to pass arguments to a compiled
applescript, but if it is, what is I doing wrong? If this isnt how to
do, how shouldt it be done?
Jon
the com.apple.cocoa classes.
I have this small Java program:
public class Test {
public static void main(String[] args) {
NSApplication.sharedApplication();
NSMutableDictionary error = new NSMutableDictionary();
String source = "";
source += "on run (mystr)\n";
source += "tell application \"Finder\"\n";
source += "display dialog \"Got a string: \" & mystr\n";
source += "end tell\n";
source += "end run\n";
NSAppleScript script = new NSAppleScript(source);
script.compile(error);
System.out.println("Error: " + error);
System.out.println("Is compiled: " + script.isCompiled());
NSAppleEventDescriptor desc =
NSAppleEventDescriptor.listDescriptor();
desc.insertDescriptor(NSAppleEventDescriptor.descriptorWithString("Hello
World"),0);
System.out.println("Desc: " + desc.stringValue());
script.executeAppleEvent(desc, error);
System.out.println("Error: " + error);
}
When running it, i get this:
Error: {}
Is compiled: true
Desc: Hello World
Error: {NSAppleScriptErrorNumber = -50; }
The ErrorNumber -50, indicates an error in the user parameter list. I
am not sure this i the right way to pass arguments to a compiled
applescript, but if it is, what is I doing wrong? If this isnt how to
do, how shouldt it be done?
Jon