Thursday, October 10, 2013
I find myself often developing on Mac OS. Given all the new technologies and programming languages available, it is sometimes easy to forget about AppleScript, a scripting language that has been available for over twenty years, and reads and writes a bit like “plain English”. AppleScript can be run from the command-line using the osascript tool, and edited and run using the “AppleScript Editor” application.
Wouldn’t it be cool if we could run AppleScripts from Factor?
Using the NSAppleScript Class
we can see that, basically, we need to create an
initialized from a source string, and then execute the script:
USING: cocoa cocoa.application cocoa.classes kernel ; : run-apple-script ( str -- ) [ NSAppleScript -> alloc ] dip <NSString> -> initWithSource: -> autorelease f -> executeAndReturnError: drop ;
Right now we are ignoring the return values, but supposedly we could figure out how to interpret the return value (which is a NSAppleEventDescriptor) and pass values back from the script to Factor.
You can see that it works by trying to display a simple dialog:
This is available in the development version of Factor.