Hack Attack: Blogging mark-up made easy

It's no secret that I'm a big fan of the open source scripting software Autohotkey, having made mention of it in both my repetitive email and Gmail master features.

In my feature about knocking down repetitive email with Autohotkey, I also mentioned that if you're a blogger, Autohotkey can make writing your HTML mark-up a whole lot easier. So for all the bloggers and HTML junkies out there, this week I'm offering my Autohotkey blogging script and executable (.exe) for download so that you don't have to go through the work of putting it together yourself.

NOTE: The executable file available for download at the end of this feature doesn't require anything to run. Just download the file and run the .exe. However, if you decide you'd like to tweak the script to your liking, you'll need to download and install the Autohotkey program.

The blogging script in action

Check out this video to get an idea of how the Autohotkey script works and how much time it can save you:

How it works

I've set up the shortcuts to be as intuitive as possible, most often using the text inside the less than (<) and greater than (>) brackets, so that putting one into action is very simple. Just type the shortcut, then press Enter.

Most of the shortcuts are as simple as:

Keyboard shortcut Replacement text
p <p></p>
br <br />
ul <ul></ul>
ol <ol></ol>
em <em></em>
h1 <h1></h1>
etc... etc...

For example, if you were to type 'p' and then immediately press Enter, the script would generate the paragraph tags, then leave your cursor in the middle of the tags. However, there are a couple of tags that I've scripted to behave differently.

For HTML tags that almost always involve a copy and paste, the script automatically pastes whatever you have copied into the clipboard to the appropriate place in the tag. This is the behavior for href's (links), blockquotes, and img (image) tags. See the video for an example of how these shortcuts work with blockquotes.

Keyboard shortcut Replacement text
hre <a href="Your Pasted Text"></a>
bk <blockquote>Your Pasted Text</blockquote>
img <img src="Your Pasted Text"></img>

My blogging/HTML script, as is, should serve as a simple starting point (and nice time saver) for picking up the pace a little when you're blogging or writing any HTML. If you find that you still have to do a lot of repetitive typing for several pre-set div's or styles, you can easily edit and add your own shortcuts to the script.

For example, at Lifehacker we have a div at the end of each post that encapsulates our outgoing links. I used to have to type this div (with a class of "related") several times every day, and after forgetting to close the div and messing up the site's formatting a couple of times, I added it to my blogging script. The same is true of the styling class for our images. It's a lot more simple on the fingers to type in a three-letter shortcut and hit Enter than it is to add classes and styles to all your divs and other HTML elements, and it makes it that much more unlikely that you'll forget to close a tag.

If you'd like to know how to edit and create your own scripts and shortcuts, check out my feature on knocking down repetitive email with Autohotkey.

Download the blogging script

You can download the executable blogging script, which you can run on any Windows machine without installing anything. Just run the blogging.exe file and you're ready to blog. [1] If you'd like to tweak the script to your own liking but don't feel like starting over from scratch, you can also download the Autohotkey (.ahk) script file to edit and customize to your heart's content. Either way, if you do anything that requires much HTML, you'll soon wonder how you lived without it.

Adam Pash is an associate editor for Lifehacker who loves keyboard shortcuts. His special feature Hack Attack appears every Tuesday on Lifehacker. Subscribe to the Hack Attack RSS feed to get new installments in your newsreader.


[1] I tried to add the most commonly used HTML tags, but if these scripts are missing some common tags that you use regularly, let me know at adam at lifehacker.com or mention something in the tips and I'll add your request to the script. [back up]