JMRI: AppleScript
On Mac OS X, you can use AppleScript to with JMRI. There are two ways to do this:- A JMRI script can use AppleScript to ask MacOS X to do things.
- AppleScripts running outside of JMRI can ask a JMRI application to do things.
Operating Your Mac from JMRI via an AppleScript
You can write AppleScript commands and programs (scripts) within JMRI jython scripts, and then invoke them to have your Mac perform functions outside JMRI. An example of this is in the AppleScript.py sample script distributed with JMRI. It executes a very simple AppleScript:
tell application "Finder"
make new folder at desktop
end tell
To do this, it has to
- Import some libraries to get access to AppleScript
- Create a string that holds the script itself
- Create some objects to interpet the script and handle errors
- Then execute the script
Controlling JMRI via an AppleScript
This section needs a lot of work; in the meantime, try
osascript -e 'tell application "DecoderPro" to get its |user.name|'
and look at the
Apple doc page.
Also, search for "AppleScript" and "System Events" on this page.
Note the need to set accessibility, mentioned on this page. This is done on the Universal Access pane of System Preferences (System row, near the bottom), represented by this checkbox at the bottom:
[ ] Enable access for assistive devices
See the sample file jython/applescript/sampleAppleScript.scpt
http://lists.apple.com/archives/java-dev/2005/May/msg00170.html
AppleScript Information
For more information on AppleScripts, including how to write and debug them, please see:- The AppleScript page on the Apple web site. The "Learn" section has useful examples.
- The WikiPedia AppleScript entry has some interesting background info.
- There's an AppleScript language guide on the Apple developer AppleScript site.
- There's a very good O'Reilly article on combining AppleScript and Java, i.e. JMRI. It covers the technical aspects of running your Mac from within JMRI.