Stupid Mac OS X Tricks: Select Word

| | Comments (0)
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.

Leave a comment

<pudge/*> (pronounced "PudgeGlob") is thousands of posts over many years by Pudge.

"It is the common fate of the indolent to see their rights become a prey to the active. The condition upon which God hath given liberty to man is eternal vigilance; which condition if he break, servitude is at once the consequence of his crime and the punishment of his guilt."

About this Entry

This page contains a single entry by pudge published on September 23, 2003 9:23 AM.

cenotaph-1.3 Released was the previous entry in this site.

DirecTV NFL Sunday Ticket Highlights is the next entry in this site.

Find recent content on the main index or look in the archives to find all content.