Scripts for WordPress and BBEdit, Part 3

If you write a lot of helper scripts that you come to depend on, you’ll probably come to realize how interdependent they are. They don’t all get written at once, of course, so they kind of accrete onto your working environment—written in whatever language seems the most appropriate at the time and saved wherever convenient. If, at some later time, you try to rationalize these scripts, you’ll learn just how many you’ve built up and how difficult it is to organize them into something that others can use.

That, at least, has been my experience in pulling together the scripts I’ve written for writing and publishing WordPress posts in Markdown format. The Scripts, Text Filters, and Clippings that actually appear in the BBEdit menus are themselves dependent on a raft of helper scripts and external libraries that are stored outside the BBEdit framework. Pulling everything together into a single package that can be downloaded and installed by someone else has been a chore, but I think it’s finally done. Many thanks to Patrick Woolsey, who mans the Bare Bones support email system, for walking my through some of the details of putting together a BBEdit package that aren’t covered in the manual. One day I’ll write a post about the tips I picked up from him, but this is not that day.

The package is called WP-MD and is available in this GitHub repository. The README describes each script and indicates whether the script needs customization, relies on non-standard libraries, or needs some other external configuration. You install it by downloading the WP-MD.bbpackage folder, customizing it as necessary, and dragging it into either

• ~/Library/Application Support/BBEdit/Packages/, or
• ~/Dropbox/Application Support/BBEdit/Packages/

depending on where you keep your BBEdit extras. I use the Dropbox option to keep my iMac and MacBook Air in sync.

There’s no need to keep every item in the package. You can trim it down by deleting anything you wouldn’t use. Just don’t delete helper scripts that other scripts rely on.

Here’s the description of the package contents from the README. As you can see, even after tidying up it’s still an oddball collection of interlocking scripts written in four languages. Despite its convoluted structure, in practice it works very smoothly, especially with well-chosen keyboard shortcuts.

Resources

These are a set of helper scripts that are called by the user-facing scripts, text filters, and clippings.

bbstdin (Shell script)
A utility script that converts BBEdit text into stdin for piping to other scripts.

• Fuller description: This blog post.
• External requirement: None.
• Needs editing: No.

get-post (Python script)
Retrieve the header and text of the specified blog post and return it in stdout.

• Fuller description: This blog post.
• External requirement: You must have a Keychain entry with a name set to the URL of the blog’s xmlrpc.php file, an account set to the blog’s username, and a password set to the blog’s password.
• Non-standard libraries: pytz, keyring
• Needs editing: The url and user variables must be personalized to the blog’s xmlrpc.php URL and username. The myTZ variable must be set to the blog’s time zone.

recent-posts (Python script)
Return a list of recent posts with post number and title for each.

• Fuller description: This blog post.
• External requirement: You must have a Keychain entry with a name set to the URL of the blog’s xmlrpc.php file, an account set to the blog’s username, and a password set to the blog’s password.
• Non-standard libraries: keyring
• Needs editing: The url and user variables must be personalized to the blog’s xmlrpc.php URL and username.

Scan text for numbered Markdown reference-style links and return the next one in the series.

• Fuller description: This blog post.
• External requirement: None.
• Non-standard libraries: None.
• Needs editing: No.

Scan text for Markdown reference-style links, display them in a dialog box, and return the one chosen by the user.

glucky (Ruby script)
Return URL of Google’s “I’m Feeling Lucky” link for the given text.

• Fuller description: This blog post.
• External requirement: None.
• Non-standard libraries: None.
• Needs editing: No.

prepend-language (Perl script)
Determine a script’s language from its shebang line (if present) and return the script with that language prepended to it.

• Fuller description: This blog post.
• External requirement: None.
• Non-standard libraries: None.
• Needs editing: No.

flickroriginal (Python script)
Return an <img> link to the Original image file shown on the Flickr page in the frontmost Safari tab.

• Fuller description: The library is described in this post.
• External requirement: None.
• Non-standard libraries: currentflickr.
• Needs editing: No, but Flickr API credentials the currentflickr library it’s based on will need to be changed.

flickr640 (Python script)
Return an <img> link to the Medium 640 image file shown on the Flickr page in the frontmost Safari tab.

• Fuller description: The library is described in this post.
• External requirement: None.
• Non-standard libraries: currentflickr.
• Needs editing: No, but Flickr API credentials the currentflickr library it’s based on will need to be changed.

flickr800 (Python script)
Return an <img> link to the Medium 800 image file shown on the Flickr page in the frontmost Safari tab.

• Fuller description: The library is described in this post.
• External requirement: None.
• Non-standard libraries: currentflickr.
• Needs editing: No, but Flickr API credentials the currentflickr library it’s based on will need to be changed.

flickr1024 (Python script)
Return an <img> link to the Large image file shown on the Flickr page in the frontmost Safari tab.

• Fuller description: The library is described in this post.
• External requirement: None.
• Non-standard libraries: currentflickr.
• Needs editing: No, but Flickr API credentials the currentflickr library it’s based on will need to be changed.

Text Filters

Publish Post.py (Python script)
Takes the current window or selection and publishes it.

• Fuller description: This blog post.
• External requirement: You must have a Keychain entry with a name set to the URL of the blog’s xmlrpc.php file, an account set to the blog’s username, and a password set to the blog’s password.
• Non-standard libraries: pytz, keyring
• Needs editing: The url and user variables must be personalized to the blog’s xmlrpc.php URL and username. The myTZ variable must be set to the blog’s time zone.

Line-Numbered Source Code.textfactory (BBEdit text factory)
Takes the selected lines, numbers the lines, indents it so Markdown will format it as source code, and prepends a language description if there’s a #! line.

Tabs to Markdown Table.pl (Perl script)
Takes a set of lines with tab-separated values and turns it into a MultiMarkdown-style table. Most useful when copying a table from a spreadsheet into a Markdown file.

• Fuller description: This blog post.
• External requirement: None.
• Non-standard libraries: None.
• Needs editing: No.

Normalize Table.py (Python script)
Takes a MultiMarkdown-style table with ragged column separators and aligns them. Intended to be used with a non-proportional font.

• Fuller description: This blog post.
• External requirements: None.
• Non-standard libraries: None.
• Needs editing: No.

Tidy Markdown Reference Links.py (Python script)
Renumbers and reorders Markdown reference links in a post.

• Fuller description: This blog post.
• External requirements: None.
• Non-standard libraries: None.
• Needs editing: No.
• Warning: Doesn’t work if the post contains sections of Markdown source code with example reference links.

Scripts

Get Recent Post (AppleScript)
Presents a list of the 15 most recent blog posts. Creates a new window with the selected post. Uses the get-post and recent-posts helper scripts.

Creates a new Markdown reference-style link, defaulting to the URL of the frontmost tab of Safari. Uses the nextreflink helper script.

• Fuller description: This blog post.
• External requirements: None.
• Needs editing: No.

Creates a Markdown reference-style link to a URL already in the document. Uses the getreflink helper script.

Creates a Markdown reference style link to the “I’m Feeling Lucky” hit on the selected text. Uses the glucky helper script.

• Fuller description: This blog post.
• External requirements: None.
• Needs editing: No.

Clippings

These are kept in a Blogging subgroup and are tied to Markdown files.

Inserts an <img> link for the Original image file shown on the Flickr page in the frontmost Safari tab. Uses the flickroriginal helper script.
Inserts an <img> link for the Medium 640 image file shown on the Flickr page in the frontmost Safari tab. Uses the flickr640 helper script.
Inserts an <img> link for the Medium 800 image file shown on the Flickr page in the frontmost Safari tab. Uses the flickr800 helper script.
Inserts an <img> link for the Large image file shown on the Flickr page in the frontmost Safari tab. Uses the flickr1024 helper script.