Archive for the 'scripting macs' Category

Book deferred; book started

I’ve deferred work on Ruby Scripting for Leopard in favor of a new venture: a book on RubyCocoa. I had two reasons for doing that:

  1. I’m unhappy with how difficult scripting is, not because of the scripting frameworks themselves, but because the apps’ interfaces are badly documented and buggy. A book documenting something that’s hard will sell less well than one documenting something easy.

    Is the bugginess going to change? Possibly, but the history of AppleScript doesn’t make me optimistic. However, this alone would not kill the book, or even defer it. But:

  2. There are two competing scripting frameworks: rb-appscript and the Apple Scripting Bridge. I’ve been writing the same scripts in both. I have no particular opinion on their different approaches, but rb-appscript is more mature. I find myself using it first, then translating a script into Scripting Bridge.

    That’s a problem. If the book treats rb-appscript, whatever comes next after Leopard could conceivably do the same thing to rb-appscript as Time Machine is doing to backup software. But I just can’t convince myself that Scripting Bridge is ready for mainstream Rubyists. I could document both frameworks, but I can also wait and see how things shake out.

Sorry for the disappointment.

I’ll be announcing a review draft of the “How Do We Get This Thing Started?” chapter later this week at the book’s mailing list.

The experience of scripting: a movie

I’ve made a video showing something of what it feels like to script a Mac application using Ruby. It also explains the basics of rb-appscript, one of the two main Ruby frameworks.

I made it after a burst of frustration with how often my scripting runs into wholly unnecessary snags. What I wish I knew is how many people who would love to script iTunes or Mail or whatever won’t because app developers make it too hard.

Perhaps I’ve stumbled into more snags than a normal human would (being a tester curses you that way). Or perhaps I overreact. Both seem to happen a lot. If you have experience with AppleScript or Ruby scripting, and you think so, let me know in comments or mail.

The video is 13 minutes long.

Offer: I’ll write a script for you

As part of working up Ruby Scripting for Leopard, I need to write piles of scripts. If you have a script you’d like to see written, drop me a line. It needs to be a script that controls applications in either /Applications or /System/Library/CoreServices. The application should be one that’s pre-installed or one that most everyone should install anyway (e.g., Quicksilver). You have to be running OS X 1.5 (Leopard).

Controlling iTunes with Ruby (alternate take)

Here’s a different version of the same playlist-generating script. This one uses rb-appscript rather than the built-in Scripting Bridge. (Raw source here.)
(more…)

Controlling iTunes with Ruby

In working on Ruby Scripting Leopard, I’ve been helped by searching for AppleScript examples, such as those at Doug’s AppleScripts for iTunes. To pay it forward, I offer an example to some future searcher after the jump. Since WordPress (or something) is turning quotes into “smart” quotes, follow this link if you want plain text.

This should work on stock Leopard.

I run it via launchd, the replacement for cron(1). Lingon is a convenient way to create a launchd configuration file.
(more…)

Soliciting reviewers and advice-givers

I’ve begun work in earnest on Ruby Scripting for Leopard. I’d like to assemble an audience who can review drafts and tell me what people like them need. I’ve set up a mailing list.

The one sentence description of the book is “How to do anything AppleScript can, but in Ruby.” That is, the main focus will be using Ruby to control other apps like Mail or Safari. It’ll also show you how to write code that makes use of Mac framework features (like sending Growl notifications and putting controllers for your scripts in the status bar). It won’t be your definitive guide to RubyCocoa, though. Most likely I won’t talk about Xcode or Interface Builder at all.

The book will assume no experience scripting Macs (or anything else). I’d like some helpers who fit that category, but also people with lots of experience.

Readers should know Ruby, but I haven’t decided how much. Certainly you needn’t be an expert. Anyone who knows Ruby to the level of my earlier Everyday Scripting with Ruby is definitely in the audience.

Thanks.

Ruby to Growl, with callbacks

I wanted to write a script that used Growl to notify a user. That user could click on the Growl sidle-up, and that would make the script do something. It took me a while to figure out callbacks from Growl to the originating app, so I thought I’d write it down.
(more…)

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.