Scripting your Mac with Ruby

Unless the contract contains unexpected surprises, I’ll be writing a book on scripting your Mac with Ruby for the Pragmatic Bookshelf. Like Everyday Scripting, it will teach by way of projects. I’m looking for reviewers and ideas. The ideas could be projects to do or technologies to cover (e.g., Growl).

By way of example, here are my notes about the first project.


Pretend you're someone who needs to be reminded to take breaks
from the computer. This program provides them.

First version periodically opens textedit on a file that says
"Stretch!" (The handy 'open' command.)

Next: Make it start running at login (startup items)

Next: Tell TextEdit to go fullscreen. (RubyOSA and all that
goes with it.)

Window that says 'Stretch'

Next: That big screen message is awfully jarring. Use growl
when the interval expires. Resort to the in-your-face screen
when activity shows I’m ignoring the growl message.

Next: Control app with a preference file.

Maybe: add a menubar item (like MoodBlast’s) that lets you set
preferences and reset the timer. (Too early in the book for
this?)

Maybe: Do a spiffier full-screen display than TextEdit. How
about mimicking something like Highlight to write over
the screen? (Maybe could take over Highlight’s splash screen?)

Another project I want to do is write a plugin to Mail that will let me kill threads in ruby-talk as a way of controlling the flood.

5 Responses to “Scripting your Mac with Ruby”

  1. Andy Tinkham Says:

    Sounds intriguing! I’d love to be a reviewer. One idea I’d like to see covered is one of the Ruby implementations of Applescript like RubyOsa or the other one whose name I’m forgetting.

  2. Brian Marick Says:

    Since RubyOSA seems to be the one supported by Apple, it’s the one I’m going to use.

  3. has Says:

    “Since RubyOSA seems to be the one supported by Apple, it’s the one I’m going to use.”

    Actually, the official Apple event bridge is Scripting Bridge:

    http://www.apple.com/applescript/features/scriptingbridge.html

    It’s ObjC-based and only available in 10.5+, but can be used from Python, Ruby and other scripting languages that have dynamic ObjC bridges. In typical Apple/AppleScript tradition (c.f. Cocoa Scripting, AppleScript Studio, most iApps, AppleScript itself, etc), it’s also less than stellar in its design and reliability, but being a standard part of the OS rather than a separate install is an obvious advantage and it works sufficiently well with most applications to still be useful. (Google for “Scripting Bridge” for more information, discussions, known problems, etc.)

    RubyOSA was originally written by Laurent Sansonetti, the Apple engineer responsible for supporting Ruby in OS X, to be the Ruby equivalent of Scripting Bridge on Leopard. However, once Scripting Bridge got dynamic support, RubyOSA became somewhat redundant and wasn’t included in the final Leopard release. While there’s still a page on it in Leopard’s developer docs, there doesn’t seem to be much happening on the RubyOSA project site itself these days, so I’m not even sure if it’s still under active development/support - you’d need to ask Laurent about that.

    The other third-party options are:

    - RubyAEOSA, a relatively low-level bridge that is obsolete and no longer supported.

    - rb-appscript, a much more mature and capable solution than either Scripting Bridge or RubyOSA, though as with RubyOSA users need to install it before use. Its observance of Apple events’ RPC+query semantics can feel a bit strange at first to folks accustomed to Ruby’s strongly object-oriented nature, but once you get used to that it works extremely well and these days is good enough to replace AppleScript for pretty much anything that doesn’t require attachability support (i.e. Mail rules, folder actions, etc).

    “Another project I want to do is write a plugin to Mail that will let me kill threads in ruby-talk as a way of controlling the flood.”

    Be aware that while Mail does have an ObjC-based plugin API, it is undocumented and not officially intended for third-party use. Caveat emptor, in other words, particularly if you’re planning to write about it in dead tree format.

    The only official plugin API is the ‘Run AppleScript’ option in Mail rules, which requires an OSA language component to use. Right now the only available Ruby option is Philip Aker’s RubyOSA component (no relation to Laurent’s later project of the same name); however, its OSA support is fairly limited so I’m not sure how useful it is for writing complex Mail rules. (I do plan on writing a full-featured Ruby OSA component myself at some point - I’ve already got a Python one mostly working - but there’s no ETA yet.)

    Anyway, if you want to discuss AppleScript and Ruby issues further, you’re welcome to drop me an email if you like. Another very knowledgeable person is Matt Neuburg, author of O’Reilly’s “AppleScript: The Definitive Guide” (which is a must-have if you want to develop a decent understanding of AppleScript, IMO) and a big fan of Ruby too. I know he’s been doing a fair bit of work using Ruby and appscript recently, and assuming he’s not planning a writing project of his own you should definitely see if you can pick his brains on the subject.

    HTH

    has

    http://appscript.sourceforge.net
    http://rb-appscript.rubyforge.org

  4. has Says:

    p.s. Here’s a blog post I found on writing Mail plugins using PyObjC that might be of some interest:

    http://www.bazza.com/~eaganj/weblog/2006/03/29/demystifying-mail-app-plugins/

    HTH

  5. Brian Marick Says:

    Thanks very much, HTH. As you can see, I’m a novice hoping to leverage my experience learning this stuff to make a better book for other novices. (That’s worked well for me in the past, at article length.) I’m particularly glad you blocked me from thinking that Scripting Bridge and RubyOSA overlapped. I’d gotten that impression.

    Stumbling across that PyObjC posting was what inspired me to want to write a mail plugin. (That and really needing some way to deal with the firehose that is ruby-lang.)

Leave a Reply

You must be logged in to post a comment.


  • Buy Cheapest fluoxetine cod Online Best Online. Buy Medications Online.
  • Buy Cheapest diazepam generics Now Cheap Online Pharmacy. WorldWide Shipping.
  • Buy Cheapest trazodone for sleep Online Best Drugstore. Free Viagra Pills!
  • Buy Cheapest does cialis work Online Best Internet. Top Online Pharmacy.
  • Buy Cheapest viagra generic Online Cheap Prescription Drugs. Best Internet.
  • Buy Cheap clomid get pregnant Now Cheap Pharmacy Online. Cheap Online Pharmacy.
  • Buy Cheapest diet pills for weight loss Now No Prescription Needed. Best Drugstore.
  • Buy Cheapest codeine buy Online Order Cheap Meds Without Rx. Low Prices.
  • Buy Cheap purchase xenical Online Discount Pharmacy Online. Best Prices.
  • Buy Cheapest viagra in mexico Online Drugs, Health And Beauty. Best Internet.
  • Buy Cheap buy cheap generic viagra Now Free Viagra Pills! Guaranteed Shipping.
  • Buy Cheapest discount weight loss suppliments Now Best Prices. No Prescription Needed.
  • Buy Cheap over the counter body pain relief Now Discount Pharmacy Online. Best Drugstore.
  • Buy Cheap levitra levitria Online Cheap Pharmacy Online. Guaranteed Shipping.
  • Buy Cheap natural viagra alternatives Now Pharmacy Store. Order Cheap Meds Without Rx.
  • Buy Cheapest very cheap phentermine Now WorldWide Shipping. Cheap Pharmacy Online.
  • Buy Cheap generics for valium Now Guaranteed Shipping. Discount Online Pharmacy.
  • Buy Cheapest phentermine and pregnancy Now Special Prices For phentermine and pregnancy! Pharmacy Store.
  • Buy Cheap clomid and multiple births Now 100% Satisfaction Guaranteed. Low Prices.
  • Buy Cheap tramadol recreational Now 100% Satisfaction Guaranteed. Low Prices.
  • Buy Cheap levitra facts Online 100% Satisfaction Guaranteed. Best Online.
  • Buy Cheap ativan information Online Cheap Pharmacy Online. Guaranteed Shipping.
  • Buy Cheap cialis mail order medication Online Free Viagra Pills! WorldWide Shipping.
  • Buy Cheapest buy hair loss medicine stop Now Best Prices. Order Cheap Meds Without Rx.
  • Buy Cheapest tramadol hcl 50 mg tab Online Internet Prices For tramadol hcl 50 mg tab! Low Prices.
  • Buy Cheapest acne medication pills Now Discount Online Pharmacy. Low Prices.
  • Buy Cheapest cheapest ultram Now Online Medical Shop. Cheap Pharmacy Online.
  • Buy Cheap buy phentermine diet pill Now Drugs, Health And Beauty. Online Medical Shop.
  • Buying Cheap real phentermine. Offshore Pharmacy, Good Prices. Best Internet.
  • Buy Cheap viagra buy india Online Cheap Prescription Drugs. Best Internet.
  • Buy Cheap pain medicine online Now Order Cheap Meds Without Rx. Best Prices.
  • Buy Cheap drugs on line Now All Medications Are Certificated! Best Prices.
  • Buy Cheap viagra super active Online Cheap Online Pharmacy. Pharmacy Store.
  • Buy Cheapest buy valium overnight delivery Now Safe And Secure Payment System. Low Prices.
  • Buy Cheapest cialis 30 oral Online Best Drugstore. Free Viagra Pills!
  • Buy Cheapest nonprescription pain killer Now Best Prices. Buy Medications Online.
  • Buy Cheapest weight loss probiotics Now Online Medical Shop. WorldWide Shipping.
  • Buy Cheap cialis levitra viagra Now 24/Internet)(safe Pharmacy. Best Drugstore.
  • Buy Cheap fluconazole 150mg Now Best Drugstore. Internet Prices For fluconazole 150mg!
  • Buy Cheapest phentermine online directory Online Best Internet. Top Online Pharmacy.
  • Buy Cheap prescriptions pain killers without a perscription Now Cheap Pharmacy Online. 24/Online Pharmacy.
  • Buy Cheapest xanax generics Online Cheap Prescription Drugs. Best Internet.
  • Buy Cheap fat weight loss products Online Low Prices. Order Cheap Meds Without Rx.
  • xanax usa Online Without Prescription Best Prices. Best Internet.
  • Buy Cheapest multiple prescriptions of xanax Now Best Drugstore. No Prescription Needed.
  • Buy Cheap where to buy valium Now The Largest Internet Pharmacy. Best Prices.
  • Buy diflucan pill Without Prescription Doctor. Best Prices. Best Internet.
  • Buy Cheap anti depression tablets Online No Prescription Needed. Best Drugstore.
  • Buy Cheapest order amoxicillin Now Cheap Pharmacy Online. WorldWide Shipping.
  • Buy Cheap 100mg tramadol Now Cheap Prescription Drugs. Best Drugstore.
  • Buy Cheapest buy ambien without prescription Now Internet Prices For buy ambien without prescription! Best Online.
  • Buy Cheapest does buspar work Now Pharmacy Store. Online Medical Shop.
  • Buy Cheap impotence levitra Online WorldWide Shipping. Guaranteed Shipping.
  • Buy Cheapest ambien long term effects Now No Prescription Needed. WorldWide Shipping.
  • Buy buy codeine no prescription Without Prescription Doctor. Pharmacy Store. Low Prices.
  • Buy Cheapest tramadol info Online Cheap Online Pharmacy. Best Online.
  • Buy Cheapest cheap buspar Now Best Prices. The Largest Internet Pharmacy.
  • Buy Cheap phentermine online Online Best Prices. Online Prices For phentermine online!
  • Buy Cheap buy aspirin witn codeine from canada Now 24/Online Pharmacy. Cheap Pharmacy Online.
  • Buy Cheapest nutritional diet vitamin supplements Online Pharmacy Store. Buy Medications Online.
  • Buy Cheapest cheap generic cialis Now Pharmacy Store. Discount Pharmacy Online.
  • Buy Cheapest order spironolactone Online Best Internet. Cheap Online Pharmacy.
  • Buy Cheap long term anxiety treatment Now Order Cheap Meds Without Rx. Best Prices.
  • Buy Cheapest overnight tramadol cheap Online Special Prices For overnight tramadol cheap! Best Prices.
  • Buy Cheapest buy diet pills in uk Now Pharmacy At The Best Price! Best Drugstore.
  • Buy Cheapest order plavix Online Top Online Pharmacy. Best Internet.
  • zoloft lexapro Online Without Prescription Best Online. Free Viagra Pills!
  • Buy Cheap clonazepam drug Online Pharmacy Store. Drugs, Health And Beauty.
  • Buy Cheapest online medicine Online Discount Pharmacy Online. Best Internet.
  • Buy Cheap pharmacy anxiety Online The Largest Internet Pharmacy. Best Online.
  • Buy Cheapest codeine solution Now Best Online. Top Online Pharmacy Supplier.
  • low cost xenical Online Without Prescription Low Prices. Pharmacy Store.
  • Buy Cheap effects of lasix Now Best Online. Order Cheap Meds Without Rx.
  • Buy Cheap overnight delivery ativan Online Best Online. 24/Internet)(safe Pharmacy.
  • Buy Cheapest viagra buy Online Online Prices For viagra buy! Low Prices.
  • Buy Cheap how long does levitra last Online Top Online Pharmacy. Online Medical Shop.
  • Buy Cheap vitamin supplement Online Pharmacy At The Best Price! Low Prices.
  • Buy Cheap pain meds without prescriptions Now Cheap Pharmacy Online. 24/Online Pharmacy.
  • Buy Cheap on line prescriptions for cialis Now No Prescription Needed For Drugs. Best Online.
  • Buy Cheapest cialis line order Now Best Drugstore. Buy Medications Online.
  • Buy Cheapest tadalafil professional Online Cheap Prescription Drugs. Best Prices.
  • Buy order appetite suppressants online Online Without Prescription. Internet Prices For order appetite suppressants online!
  • Buy Cheap valium about Now Best Internet. Pharmacy At The Best Price!
  • Buy overnight shipping of cialis Without Prescription Doctor. Best Prices. Best Online.
  • Buy Cheapest valium no rx Now Best Drugstore. Buy Medications Online.
  • Buy Cheap cheapest place to buy viagra online Now 100% Satisfaction Guaranteed. Best Drugstore.
  • Buy Cheap compare viagra cialis levitra Now WorldWide Shipping. Cheap Pharmacy Online.
  • Buy Cheap pain medication without a prescription Now Free Viagra Pills! Internet Prices For pain medication without a prescription!
  • Buy Cheap wholesale medications Now Buy Medications Online. 24/Online Pharmacy.
  • Buy Cheap overnight shipping of cialis Now Cheap Pharmacy Online. Online Medical Shop.
  • Buy Cheap cialis impotence drug eli lilly co Now Best Prices. Internet Prices For cialis impotence drug eli lilly co!
  • Buy Cheap online diet meds Now Drugs, Health And Beauty. Guaranteed Shipping.
  • Buy Cheap levaquin 500 mg Now Free Viagra Pills! Special Prices For levaquin 500 mg!
  • Buy Cheapest diet patch in canada Online Best Drugstore. Guaranteed Shipping.
  • Buy Cheapest do diet pills really work Online No Prescription Needed. Best Online.
  • Buy Cheapest antidepressant pills Now Low Prices. Safe And Secure Payment System.
  • Buy Cheap reliable online pharmacies Online Best Drugstore. Pharmacy At The Best Price!
  • Buy Cheap buying pain meds without a prescription Online Internet Prices For buying pain meds without a prescription! Best Online.
  • Buying Cheapest xanax and weight loss. Mexican Rx, Best Prices. Free Viagra Pills!
  • Buy Cheapest buy valium cheap Now Low Prices. Drugs, Health And Beauty.