tags:

views:

91

answers:

4

When it comes to scripting the Mac, are there alternatives to Applescript? It's API seems awesome, but the language it self, from what I've read so far, seems aimed more at non-programmers.

Insights into this would be great helpful.

(At the moment, I'm thinking of writing a tiling window manager for the Mac). Yes, I know some exist, but this will be open source. Yes, I know of Xmonad, but it only does X11 windows.

Thanks!

A: 

There are bridges to AppleScript from ruby, objective-c and others.

Alex Brown
+2  A: 

If Ruby is your thing you could use RubyOSA which allows one to use Ruby to interact with Apple's Event Manager:

http://rubyosa.rubyforge.org/

Cody Caughlan
Note that the original RubyOSA project is no longer actively maintained or supported. I think there is a third-party fork on github that addresses compatibility problems with newer versions of Ruby; that said, there are more capable and reliable alternatives that are actively supported.
has
+1  A: 

Check out MacRuby. There are also interesting approaches with Python (mainly for writing plugins) and TCL/TK.

Maybe not the thing for the purpose you describe, but there also is Quartz Composer, a widely unknown but interesting visual programming environment with a lot of potential.

Dieter
+4  A: 

When it comes to scripting the Mac, are there alternatives to Applescript?

Depends what you want to do. If you want to send Apple events to other applications, yes; for running scripts from OSA-aware applications (Mail rules, folder actions, etc.), not really.

The best technical alternative is appscript (my baby), which is available for Python, Ruby and Objective-C on 10.4+. (There's also a MacRuby version, but I've yet to do a public release of that.) Feature-wise appscript's slightly better than AppleScript and its application compatibility is very nearly as good. Third-party project, so you'll need to install it yourself (but that's easy enough as long as you've got Xcode) and MIT licensed so you can redistribute it as needed (e.g. included in your application bundle). Fairly decent tool and documentation support, including an online book by Matt Neuburg, with mailing list support for the Python and Ruby versions and direct email support for the others.

The 'official' alternative is Apple's Scripting Bridge. The API looks very Cocoa-like, but that's really just a lot of smoke and mirrors which ultimately makes it less capable than AppleScript and significantly more prone to application compatibility problems (and tricky to troubleshoot when it does go wrong). Tool, documentation and community support is not so great either (appscript's is better; AppleScript's is better still). SB's main advantage is that it's included in 10.5+ so requires no additional installation to use. I wouldn't recommend it for heavy-duty automation work due to its technical shortcomings, but for modest automation tasks involving obliging apps it may suffice.

Other bridges do exist (e.g. Perl's Mac::Glue, RubyOSA), but they are not as capable, popular and/or actively supported.

All that said, if you want to do any serious application scripting, you will still have to learn AppleScript as that's where you'll find the vast bulk of literature, sample scripts and community expertise. All of which you will need, since the great majority of scriptable applications are notoriously under-documented.

has
Nice work, appscript looks pretty cool.
Cody Caughlan