In part I failed because of Safari, and the way it structures extensions. Briefly, Safari uses a sort of separation-of-concerns model, so what a particular piece of an extension can access varies. Getting the selection is really hard because you need to use proxying and messaging to communicate between the current page, the extension’s “page”, and any resources.
I gave up because it sucked and wasn’t fun.
I had another thought: use Applescript to get the selection and pass it to the Delibar app itself! GENIUS!
The tl;dr here is “Delibar isn’t scriptable” so none of this matters, anyway.
Safari’s Applescript dictionary doesn’t include the term “selection”. To the best of my knowledge, you cannot use Applescript to get the selection of the current tab. Oh ….. kay.
Here’s the relevant bits from the dictionary:
and the example:
Makes sense, right? Sure. So you’d pretty much imagine that it works just like this:
- adding a return
- wrapping it in an anonymous function
- using document instead of window
banging my head against the desk and cursing myself for ever having these sorts of thoughts After lots of searching, I discovered the completely obvious answer:
That’s a double-quote, left paren, single quote, single quote, plus, then the function and a closing quote.
Of course. Completely obvious. Note that removing the single quotes and concatenation operator doesn’t work. So “(foo())” doesn’t work, but “(”+foo())” does. I found two places that say it does work, but I can’t make it happen in the latest Lion and Safari.
How the hell do you even arrive at that as a logical place. And how do you expect regular people, ostensibly the target market for Applescript, to arrive at that conclusion?
Applescript is goddamned awful.