Skip to content

Instantly share code, notes, and snippets.

@daniel42
Created March 8, 2010 03:50
Show Gist options
  • Save daniel42/324836 to your computer and use it in GitHub Desktop.
Save daniel42/324836 to your computer and use it in GitHub Desktop.
import javax.script.*;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) throws FileNotFoundException, ScriptException {
// Setup various objects
ScriptEngineManager engineManager = new ScriptEngineManager();
ScriptEngine applescript = engineManager.getEngineByName("AppleScript");
String testFile = "test.applescript";
String testString = "Hello From Java!";
System.out.println("Running the Script");
// javax_script_function is the entry point function that gets called in our script
// i.e. it's the main
applescript.put("javax_script_function", "growlNotification");
// Need a List to pass multiple arguments into the script
List<String> l = new ArrayList<String>();
l.add("Java");
l.add(testString);
// Passing arguments into the script
applescript.put(javax.script.ScriptEngine.ARGV, l);
// Now evaluate the script.
Object o = applescript.eval(new FileReader(testFile));
System.out.println("Output: " + o);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment