How to execute AppleScript from a Java or Scala application
Briefly

If you ever need to execute AppleScript from a Java or Scala application, this code shows how to solve the programming part of this problem.Given an AppleScript command as a Scala multiline string, like this:

// press the `fn` key twice
val asCommand = """
tell application "System Events"
   key code 63
   key code 63
end tell
"""

you can execute that command by calling this executeAppleScriptCommand method:

val succeeded = executeAppleScriptCommand(asCommand)

whose source code is shown here:

/**
* Executes the AppleScript command you supply as a String.
Read at Alvinalexander
[
add
]
[
|
|
]