For a long time now I have been working on learning AppleScript, where "working on" means I bought an AppleScript book that sits on my table accusingly, but I've never actually picked it up and read through it. AppleScript is clearly a powerful and relatively easy way to get somewhat complex tasks accomplished on your Mac; heck with AppleScript Studio you can even write stand-alone applications of a sort. This story on MacDevCenter, however, has given me pause. AppleScript guru Matt Neuburg (who literally wrote, if not the, at least a book on AppleScript) has put up a nice tutorial on replacing AppleScript with rb-appscript, which is "a high-level, user-friendly Apple event bridge that allows you to control scriptable Mac OS X applications using ordinary Ruby scripts." Now everybody and his brother has been going on of late about how wonderful Ruby is for web development, particularly with Rails using TextMate, so now I have a dilemma. Should I actually try to learn Ruby instead and double my return, as it were? While I think that over, go check out Matt's tutorial and see for yourself how Ruby and Apple events can make beautiful music together.[Via MacVolPlace]













Reader Comments (Page 1 of 1)
3-01-2007 @ 7:58AM
Dave said...
Or you could use this:
http://rubyosa.rubyforge.org/
It's being developed by people who work for Apple. Not sure how "official" it is, though. It would be nice if we saw it in Leopard.
Reply
3-01-2007 @ 8:04AM
Olemle said...
I was pleased to learn about this. Applescript is great for many reasons, but very bad because every script you code makes you feel as if you're coding up a Hieronomous Bosch painting in code.
Life is much easier if you can do away with the Applescript syntax, which was an interesting, but failed experiment in making computer language close to natural human language. Underline that "failed" part a few times.
Reply
3-01-2007 @ 9:32AM
Jim said...
I don't know about the Applescript bridge, but Ruby is fun and wonderful to learn and use. Plus, there is a big added bonus: you can use the RubyCocoa bridge with Xcode to write native Cocoa applications, no need to learn Objective-C!
RubyCocoa 1.0 is to be included with Leopard, but a preview version is available at:
http://rubycocoa.sourceforge.net/doc/unstable/
Documentation (for earlier versions, but still mostly applicable) is here:
http://rubycocoa.sourceforge.net/
Reply
3-01-2007 @ 9:50AM
Mark Scrimshire said...
The problem with learning AppleScript is that you can struggle for a week trying to solve some knotty problem and when you have it working someone comes along and says
Why didn't you just use the line...
Do Magic on Problem
Or some other similar voodoo...
But seriously - I love the capability of applescript having written some crude Addressbook scripts (see blog.ekive.com) that integrate with Google Calendar. The idea of a ruby interface is extremely appealing. I must go check it out.
Reply
3-01-2007 @ 10:32AM
brian said...
Just depends on who you are, what coding experience you have, and what you plan to use it for. I think Ruby is good for making really program-y type stuff (lots of abstraction, object-oriented, etc.) but AppleScript is probably simpler for small jobs, unless you're already VERY experienced with Ruby and/or object-oriented programming. Plus AppleScript is built-in and comes with dictionaries for all apps. I'm not sure how complete all the Ruby stuff is. But look at the "Hello, World!" examples and decide for yourself:
Applescript:
tell application "BBEdit"
make new document
tell document 1
set its text to "Hello, world!"
end tell
end tell
Ruby:
#!/usr/bin/env ruby
require "appscript"
include Appscript
bb = app("BBEdit")
bb.make(:new => :document)
bb.documents[1].text.set("Hello, world!")
Reply
3-01-2007 @ 12:03PM
Gerald Buckley said...
Mat - If you never pick up the Ruby book (or visit the site or whatever) then you'll be just as successful learning it as you have with Applescript.
Just learn something. Hell, anything! Just don't do "nothing" toward your goal.
Reply
3-01-2007 @ 10:17PM
Mike said...
Matt Neuberg hates AppleScript. His book (the one with the dog on the cover) is the most joyless miserable book I own. He fails to understand that the language is fun, and it appeals to be people who--unlike him--like to have fun. It upsets me that people are so often recommended to and discouraged by his work. There are better alternatives out there.
Reply
3-02-2007 @ 6:37PM
has said...
Brian: rb-appscript provides the same level of application scripting support as AppleScript, and tools for displaying application dictionaries in Ruby format are provided (see the rb-appscript website for details). The only thing you can't do with rb-appscript is attachability (Mail Rules, Folder Actions, AS Studio, etc.) as appscript is only an Apple event bridge, not a full OSA language like AppleScript. Work is already underway on developing full OSA versions of other languages though.
Mike: that's a bit unfair. It's true that Matt isn't a huge fan of the AppleScript language itself (heck, even its original designer admits it has flaws), but he's long been a strong supporter of Mac application scripting (his Frontier book spent several chapters on the subject, for example) and deserves credit for continuing to promote it. Especially to the sorts of audiences that AppleScript has traditionally failed to reach, such as professional programmers; after all, can't have scriptable applications without developers willing to write them!
As to his AppleScript book, my own feeling is that non-programmers and occasional light users may find it a bit too technical and heavy going, and would be better served by one of the other AppleScript books out there. For advanced AppleScript users, Unixy folk and application developers looking for a deep, comprehensive technical guide to AppleScript that isn't afraid to discuss its numerous deficiencies as well as its better points, however, I do think it's _the_ book to get.
(Oh, and as a postscript: even us Python and Ruby geeks like to have a little fun sometimes. Behold, iTunes from the command line:
http://rubyforge.org/forum/forum.php?forum_id=12587
Just because we can.:)
has
--
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org
Reply
3-03-2007 @ 3:20AM
Mike said...
HAS, thanks for taking time to write your reasoned reply to my comment about Matt -- which is reaction in part to a negative personal encounter I had with him in the past. Some day I'll write my own bridge that uses the AppleScript language to drive Ruby and the rest just to spite all the joyless left-brained bean counters. :p (jk--not that talented)
Reply