日期:2014-05-20  浏览次数:20781 次

Java调用AppleScript
小弟想在Mac OS S上写一个程序,在Mac OS X上运行的,需要调用AppleScript,各位大虾能否告知在Mac OS X上如何的Java如何调用AppleScript?还是根本就不能调用的,小弟新手,请大虾指教,谢谢啦!

------解决方案--------------------
Java code
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class Test {
    public static void main( String[] args ) throws ScriptException {        
        ScriptEngineManager mgr = new ScriptEngineManager();        
        
        ScriptEngine engine = mgr.getEngineByName("AppleScript");
        engine.eval( "tell application \"iTunes\" to play" );        
    }
}