Scripts for WordPress and BBEdit, Part 3
August 31, 2013 at 8:50 AM by Dr. Drang
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
anduser
variables must be personalized to the blog’sxmlrpc.php
URL and username. ThemyTZ
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
anduser
variables must be personalized to the blog’sxmlrpc.php
URL and username.
nextreflink (Python script)
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.
getreflink (Python script)
Scan text for Markdown reference-style links, display them in a dialog box, and return the one chosen by the user.
- Fuller description: This blog post.
- External requirement: The CocoaDialog application.
- Non-standard libraries: None.
- Needs editing: No.
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
anduser
variables must be personalized to the blog’sxmlrpc.php
URL and username. ThemyTZ
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.
- Fuller description: The text factory, the JavaScript function for formatting line numbers, and the syntax highlighting JavaScript library.
- External requirement: The JavaScript described above.
- Needs editing: Yes, you’ll probably have to reset the Unix filter in the fourth step of the factory to the
prepend-language
script in the package’sResources
folder. The connection to that script often gets broken when I move the package.
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.
- Fuller description: This blog post.
- External requirements: Same Keychain entries as the Publish Post text filter and the CocoaDialog application.
- Needs editing: No.
New Reference Link (AppleScript)
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.
Old Reference Link (AppleScript)
Creates a Markdown reference-style link to a URL already in the document. Uses the getreflink
helper script.
- Fuller description: This blog post.
- External requirements: The CocoaDialog application.
- Needs editing: No.
Google Lucky Link (AppleScript)
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.
Post header
Inserts a post template with fill-in spots for the title, keywords, and body. The publication date is given an initial value of two hours from the time the clipping is inserted.
Flickr original image
Inserts an <img>
link for the Original image file shown on the Flickr page in the frontmost Safari tab. Uses the flickroriginal
helper script.
Flickr 640 image
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.
Flickr 800 image
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.
Flickr 1024 image
Inserts an <img>
link for the Large image file shown on the Flickr page in the frontmost Safari tab. Uses the flickr1024
helper script.