AppleScriptEngine.java revision 5089
2362N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 0N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 2362N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A * or visit www.oracle.com if you need additional information or have any 0N/A * AppleScriptEngine implements JSR 223 for AppleScript on Mac OS X // System.out.println(AppleScriptEngine.class.getName() + "." + str); * Accessor for the ScriptEngine's long name variable * @return the long name of the ScriptEngine * Accessor for the ScriptEngine's version * @return the version of the ScriptEngine TRACE(
"getEngineVersion()");
* Accessor for the ScriptEngine's short name * @return the short name of the ScriptEngine * Accessor for the ScriptEngine's supported language name * @return the language the ScriptEngine supports * The no argument constructor sets up the object with default members, * a factory for the engine and a fresh context. * @see com.apple.applescript.AppleScriptEngine#init() // set our parent factory to be a new factory // set up our noarg bindings * All AppleScriptEngines share the same ScriptEngineFactory * The local context for the AppleScriptEngine * The constructor taking a factory as an argument sets the parent factory for * this engine to be the passed factory, and sets up the engine with a fresh context * @see com.apple.applescript.AppleScriptEngine#init() // inherit the factory passed to us // set up our noarg bindings * The initializer populates the local context with some useful predefined variables: * <ul><li><code>javax_script_language_version</code> - the version of AppleScript that the AppleScriptEngine supports.</li> * <li><code>javax_script_language</code> - "AppleScript" -- the language supported by the AppleScriptEngine.</li> * <li><code>javax_script_engine</code> - "AppleScriptEngine" -- the name of the ScriptEngine.</li> * <li><code>javax_script_engine_version</code> - the version of the AppleScriptEngine</li> * <li><code>javax_script_argv</code> - "" -- AppleScript does not take arguments from the command line</li> * <li><code>javax_script_filename</code> - "" -- the currently executing filename</li> * <li><code>javax_script_name</code> - "AppleScriptEngine" -- the short name of the AppleScriptEngine</li> * <li><code>THREADING</code> - null -- the AppleScriptEngine does not support concurrency, you will have to implement thread-safeness yourself.</li></ul> /* TODO -- name of current executable? bad java documentation at: // TODO -- for now, err on the side of caution and say that we are NOT thread-safe * Uses the AppleScriptEngine to get the local AppleScript version * @return the version of AppleScript running on the system TRACE(
"AppleScriptEngine.getLanguageVersion()");
* Implementation required by ScriptEngine parent<br /> * Returns the factory parent of this AppleScriptEngine * Implementation required by ScriptEngine parent<br /> * Return the engine's context * @return this ScriptEngine's context * Implementation required by ScriptEngine parent<br /> * Set a new context for the engine * @param context the new context to install in the engine * Implementation required by ScriptEngine parent<br /> * Create and return a new set of simple bindings. * @return a new and empty set of bindings * Implementation required by ScriptEngine parent<br /> * Return the engines bindings for the context indicated by the argument. * @param scope contextual scope to return. * @return the bindings in the engine for the scope indicated by the parameter * Implementation required by ScriptEngine parent<br /> * Sets the bindings for the indicated scope * @param bindings a set of bindings to assign to the engine * @param scope the scope that the passed bindings should be assigned to * Implementation required by ScriptEngine parent<br /> * Insert a key and value into the engine's bindings (scope: engine) * @param key the key of the pair * @param value the value of the pair * Implementation required by ScriptEngine parent<br /> * Get a value from the engine's bindings using a key (scope: engine) * @param key the key of the pair * @return the value of the pair * Implementation required by ScriptEngine parent<br /> * Passes the Reader argument, as well as the engine's context to a lower evaluation function.<br /> * Prefers FileReader or BufferedReader wrapping FileReader as argument. * @param reader a Reader to AppleScript source or compiled AppleScript * @return an Object corresponding to the return value of the script * @see com.apple.applescript.AppleScriptEngine#eval(Reader, ScriptContext) * Implementation required by ScriptEngine parent<br /> * Uses the passed bindings as the context for executing the passed script. * @param reader a stream to AppleScript source or compiled AppleScript * @param bindings a Bindings object representing the contexts to execute inside * @return the return value of the script * @see com.apple.applescript.AppleScriptEngine#eval(Reader, ScriptContext) * Implementation required by ScriptEngine parent<br /> * This function can execute either AppleScript source or compiled AppleScript and functions by writing the * contents of the Reader to a temporary file and then executing it with the engine's context. * @return an Object corresponding to the return value of the script // write our passed reader to a temporary file // read in our input and write directly to tmpfile /* TODO -- this may or may not be avoidable for certain Readers, * if a filename can be grabbed, it would be faster to get that and * use the underlying file than writing a temp file. // set up our context business * Implementation required by ScriptEngine parent<br /> * Evaluate an AppleScript script passed as a source string. Using the engine's built in context. * @param script the string to execute. * @return an Object representing the return value of the script * @see com.apple.applescript.AppleScriptEngine#eval(String, ScriptContext) * Implementation required by ScriptEngine parent<br /> * Evaluate an AppleScript script passed as a source string with a custom ScriptContext. * @param script the AppleScript source to compile and execute. * @param scriptContext the context to execute the script under * @see com.apple.applescript.AppleScriptEngine#eval(String, ScriptContext) * Implementation required by ScriptEngine parent * Converts a ScriptContext into an NSDictionary * @param context ScriptContext for the engine * @return a pointer to an NSDictionary