| Sign In/My Account | View Cart |
| Article: |
Controlling Your Mac with AppleScript and Java | |
| Subject: | Panther problems | |
| Date: | 2003-12-17 13:22:04 | |
| From: | sdwr98 | |
|
Response to: Panther problems
|
||
|
I'm not seeing this problem... I did an Archive and Install of Panther, then got all the latest software updates.
|
||
Showing messages 1 through 2 of 2.
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."); }
}