Created
March 8, 2010 03:50
-
-
Save daniel42/324836 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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