advertisement

Article:
  Controlling Your Mac with AppleScript and Java
Subject:   Panther problems
Date:   2004-01-18 18:11:53
From:   coderanger
Response to: Panther problems

I am seeing the same thing. I even modified your code to compile a text script and execute it. A simple finder directory item list takes over 2 minutes real time when I execute using "time" to measure it. I an runnign on a pristin 12" powebook that same with Panther installed. I am going to try doing and exec of 'osascript' to see if that is better.


Here is my code (modified from yours). It takes one command-line arg--a text fiel that is an Applescript.


public class RunScript
{
public static void main(String[] args)
{
// shared NSApplication
NSApplication.sharedApplication();

// read in script file
String scriptText = "";
try {
BufferedReader inStream = new BufferedReader(new FileReader(args[0]));
String inputLine;

while ((inputLine = inStream.readLine()) != null) {
scriptText += inputLine + "\n";
}
} catch (IOException e) {
System.out.println("IOException: " + e );
System.exit(1);
}


// Script Object creation and execution
NSAppleScript scriptObj = new NSAppleScript(scriptText);
// dict for script exec errors
NSMutableDictionary errorInfo = new NSMutableDictionary();
// compile
boolean compileResult = scriptObj.compile(errorInfo);
System.out.println("Compile status:" + compileResult);
// execute
System.out.println("Running script...");
NSAppleEventDescriptor aeResult = scriptObj.execute(errorInfo);

// status report
System.out.println("Script results complete..");

if (aeResult != null ) {
int itemCount = aeResult.numberOfItems();
System.out.println("Found " + itemCount + "items in aeResult.");

// print results
NSAppleEventDescriptor subDescriptor;

for(int i = 1; i <= itemCount; i++)
{
subDescriptor =
aeResult.descriptorAtIndex(i);
System.out.println(" " + subDescriptor.stringValue());
}
}
else {
System.out.println("aeResult was null.");
}
// status
System.out.println("Script run complete."); }
}



1 to 1 of 1
  1. Panther problems
    2004-04-14 18:01:03  TToolsSeth [View]

1 to 1 of 1