Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

pudge (1)

  (email not shown publicly)
AOL IM: Crimethnk (Add Buddy, Send Message)

I run this joint, see?

Journal of pudge (1)

Tuesday September 23, 2003
11:23 AM

Stupid Mac OS X Tricks: Select Word

[ #14858 ]

John Gruber wrote a Select Word script for BBEdit. Here's a Mac::Glue version.

use Mac::Glue ':glue';
$b = new Mac::Glue 'BBEdit';
$w = $b->obj(window => 1);
$o = $w->prop(offset => of => 'selection')->get;
$w->obj(word => gLast, words => whose(offset => l_e => $o))->select;

This script is pretty straightforward, apart from the odd "property => of => property" syntax. It's my most hated thing about the Mac::Glue syntax. In obj(), you normally have key/value pairs for class/value. With prop(), it's the same, except that there is a property first (prop(foo) it is just a shortcut for obj(property => foo)).

However, when you are taking a property of a property, you can't just do prop(foo => bar), because then Mac::Glue thinks foo is a class and bar is its value.

Suggestions on how to fix this syntax, as always, are welcome. :-)

Anyway, another little oddity -- not a big problem, but something to get used to -- is that where the AppleScript version says "last word whose ...", the Mac::Glue version more closely models what is actually happening, which is "last word of (words whose ...)".

Updating the above script to John's final version is an exercise left to the reader.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.