Stupid Mac OS X Tricks: Select Word
John Gruber wrote a Select Word script for BBEdit. Here's a Mac::Glue version.
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.
use Mac::Glue ':glue';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)).
$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;
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
Updating the above script to John's final version is an exercise left to the reader.
Leave a comment