|
|
| Welcome to the Mac Forums forums. Please read the FAQ if you have questions. Register to participate. |
|
|||||||
| TouchArcade.com - iPhone Game Reviews and News |
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
|
#1 |
|
Contributor
Join Date: Nov 2005
Location: Oxford, UK
|
Run Applescript from java
I am trying to run the following code, when the RunAppleScript method is launched it comes up with the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/apple/cocoa/foundation/NSAppleScript at Copying.RunApplescript(Copying.java:141) at Copying.main(Copying.java:161) line 141 is 'NSAppleScript myScript =new NSAppleScript(script);' Code:
import com.apple.cocoa.foundation.*;
import com.apple.cocoa.application.*;
public class test{
public static void RunApplescript(String script){
// This creates a new NSAppleScript
// object to execute the script
NSAppleScript myScript =new NSAppleScript(script);
// This dictionary holds any errors that are
// encountered during script execution
NSMutableDictionary errors =
new NSMutableDictionary();
// Execute the script!
NSAppleEventDescriptor results=myScript.execute(errors);
}
}
|
|
|
|
| Eraserhead |
| View Public Profile |
| Find More Posts by Eraserhead |
|
|
#2 | |
|
macrumors 601
Join Date: Jul 2002
Location: Fox Lake, IL
|
Quote:
__________________
|
|
|
|
|
|
|
#3 | |
|
Thread Starter
Contributor
Join Date: Nov 2005
Location: Oxford, UK
|
Quote:
I have typed this into Terminal 'javac -classpath "/System/Library/Java/:." Test.java' and the same error occurs. As I am using XCode I have also tried putting '-classpath /System/Libray/Java/' in the Build Tab of the inspector for Test.java I don't know if I'm doing it correctly... |
|
|
|
|
| Eraserhead |
| View Public Profile |
| Find More Posts by Eraserhead |
|
|
#4 | |
|
macrumors 601
Join Date: Jul 2002
Location: Fox Lake, IL
|
Quote:
guess I could try really quick.
__________________
|
|
|
|
|
|
|
#5 | |
|
macrumors 601
Join Date: Jul 2002
Location: Fox Lake, IL
|
Quote:
You also don't have a main method, make sure you include one in your class.
__________________
|
|
|
|
|
|
|
#6 | |
|
Thread Starter
Contributor
Join Date: Nov 2005
Location: Oxford, UK
|
Quote:
, the code isCode:
import com.apple.cocoa.foundation.*;
import com.apple.cocoa.application.*;
public class Test {
public static void RunApplescript(String script){
// This creates a new NSAppleScript
// object to execute the script
NSAppleScript myScript =new NSAppleScript(script);
// This dictionary holds any errors that are
// encountered during script execution
NSMutableDictionary errors =
new NSMutableDictionary();
// Execute the script!
NSAppleEventDescriptor results=myScript.execute(errors);
}
public static void main (String args[]) {
String cmd="tell application \"Finder\" \n"+"make new folder in folder \"Matthew's HD\" with properties{name:\"testing\"} \n"+"end tell";
RunApplescript(cmd);
}
}
|
|
|
|
|
| Eraserhead |
| View Public Profile |
| Find More Posts by Eraserhead |
|
|
#7 |
|
macrumors 601
Join Date: Jul 2002
Location: Fox Lake, IL
|
don't forget the -classpath on your java command too.
this worked fine for me. Code:
javac -classpath /System/Library/Java Test.java sudo java -classpath "/System/Library/Java:." Test
__________________
|
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|