I just said what I said and it was wrong
Or was taken wrong

A few weeks ago, I described an AppleScript I invoked, via FastScripts, to help me embed tweets into my blog posts. I called it “Tweet screenshot & link,” and it

Brought up the screenshot crosshairs—just like pressing ⇧⌘4—so I could draw a rectangle around the portion of the tweet page I wanted to use.

Resized the screenshot to fit.

Uploaded the image to my server.

Grabbed the tweet URL.

Created a line of HTML that would display the image and have it act as a link to the original tweet page. The image’s alt parameter was set to the tweet text for both accessibility and searchability.

Put that HTML on the clipboard for later pasting into a blog post.

It worked pretty well, and did a lot of things with little effort on my part. I’ve used it several times since, but now I have a better system based on Blackbird Pie, something that’s been around for several months, but which I wasn’t aware of until I read about the Blackbird Pie plugin for WordPress.

The advantage of Blackbird Pie is that it displays the tweet as text, not an image. Links within the tweet work, too. Here’s an example:

Of course, instead of just using the WordPress plugin directly, the way any normal person would, I had to do some customizing. In fact, I’m not using the plugin at all; I’m using a fork of Jeff Miller’s cleverly named blackbird.py Python script/library. Like the plugin, Miller’s code generates the HTML for the embedded tweet, but it’s more general and can be used outside of WordPress. Also, it’s written in a language I feel more comfortable with, making it more easy for me to customize.

It includes, as a separate file, an AppleScript I use as a TextExpander snippet to invoke blackbird.py. The abbreviation associated with the snippet is ;tweet, which follows my usual snippet design convention.

Yes, it’s almost 2k of text, but it’s smaller than a screenshot would be, and it scales with the user’s default font size. A nice touch for embedding—due entirely to Miller; I didn’t touch this part of the code—is the use of an absolute date rather than the Twitter-standard relative date. A date like “137 days ago” isn’t really very helpful.

If you like the idea of embedding tweets this way but don’t like the style choices I’ve made, you can easily fiddle with the code to make it look the way you want. All the CSS is in the TWEET_EMBED_HTML string near the top of blackbird.py.

Update 11/9/10
And I should have guessed the embedded tweet would look like shit in the RSS feed. Expect some tweaking in the days to come.

Update 11/10/10
The look of embedded tweets in the RSS feed is more or less fixed now. The repository has the latest code.

I haven’t generalized the snippet to work with Chrome yet, because I wrote it on my G4 iBook, which can’t run Chrome. As soon as I get a chance to play with it on my Intel iMac, I’ll get it working in Chrome, too. ↩︎