This page gives a brief intro about making your application scriptable, i.e. via AppleScript.
Summary of the steps necessary:
- Process incoming AppleEvent requests in the App.HandleAppleEvent event handler.
- Write a AppleScript Vocabulary (sdef) describing the available commands (check out the Sdef editor).
- When building your app, add the sdef file to the app's Resources folder, and add two keys to the app's Info.plist file to let OS X know that this app is scriptable.
The demo shows how to handle a few custom commands where values (text or number) are passed as arguments and a value is then returned after the command has been handled by the Xojo code inside App.HandleAppleEvent.
See the Notes section in the App class for more information and instructions.
- Developing AppleScriptable Xojo Applications
- Thomas Reed wrote an article on adding scriptability to Xojo (REALbasic) apps back in issues 1.5 and 1.6 (April/May and June/July 2003) of the REALbasic Developer magazine, now xdev. It goes into more depth, along with using classes so that one can write "set x of window 1 to 123". Ignore the parts on writing an 'aete' resource and using the EightyRez app, though. That's outdated and is replaced by using 'sdef' files now. Here's an updated version of the sample code.
- To debug, use these commands to enable output of sent and received AEdesc to the Terminal:
Then launch the built app from the same terminal cmd line, using the app's path plus
/Contents/MacOS/executableName (the open command won't work for this).