mnemmonicWilliam Gibson, the father of cyberpunk, once said that the street finds its own uses for things. Without getting into a whole lot of literary analysis, he was talking about how people, especially those living without a lot of money, tend to find surprising ways to utilize what they have at hand.

Speaking of people living without a lot of money – librarians.

I don’t know how your library works, but I don’t always have the money or the approval to buy certain things when I absolutely need them. And that, my friends, is assuming I can buy it at all. What I need may not even exist. It has to be created, and who’s going to pay someone to create, build, and/or develop something?

As a Circulation Librarian in charge of the third busiest Circulation Department in the system, I face some really odd and interesting problems. In this two part series first part of an new series,* I’m going to talk about a couple problems vexing me and my branch and how I solved them. I’m also going to talk about AutoHotkey, which helped me solve them. With a little luck, you can take something away with you to help you fix up a few issues in your branch, be it large or small.

So, let’s get started, shall we?

The Problem: The $350,000 State of the Art Robot Who Can’t Call For Help

I have got the coolest machine.

It’s an FKI Logistex LibraryMate self check-in machine with a nine bin sorting system along with a staff induction unit. If that doesn’t mean anything to you, let me break it down like this. I’ve got a machine where patrons can drive up to the outside of the building, feed their materials into a reader, the machine checks them in, and then sorts the materials into one of nine bins for easy slipping and reshelving. We’ve also got a feed on the machine inside that allows the staff to do the same thing.

It’s incredibly rad. In 17 years of public library circulation, it’s the first labour saving device I’ve seen that actually saves labour.

Basically, this is a robot. It uses a combination of three RFID readers along with laser scanners to read the barcode or RFID tag on an item. After it reads the tag or the barcode, it contacts the ILS, checks the item in, receives information about what the item is, and then it uses that information to figure out which bin that item goes in. As a technologically minded library guy, this thing is like electric sex.

But it’s not without its flaws.

While the machine comes with a little app that you can install on any locally networked computer, all that app does is pop up when there’s a problem. So if the machine is jammed, shuts down, or otherwise goes inoperative this little programme throws up a window to let you know.

Sure, that’s very handy… if you happen to be sitting there at the desk and looking at the computer. So, what if you’re not?

Well normally, you’re hosed. That’s exactly what I was on the weekends when it went down and no one was working. See, the library is closed on Sunday. Thus from Saturday night to Monday morning, the machine is on its own. Then, one Monday, I came in to find this:


What’s more,you see those rolling bins in front of that mountain of books? One of those was also filled with returned items. It took us over an hour to get all of it checked in and then another hour or so getting the machine emptied and the stuff onto trucks for shelving. I thought to myself, “I’ve got a little piece of sci-fi in my check-in room using radio and lasers to check items in, and it can’t call for help when it goes down?”

That’s just unacceptable.

So I told my boss that I had a goal: By the end of the week, I’d develop a bit of software that allows that machine to let someone know it’s broken, even when we’re nowhere near the library. Thankfully, there’s a very easy way for this to happen, and millions of people do it everyday.

I’d have it send a text message to my cell phone.

The Solution

Making some notes on paper, I developed a workflow and architecture for this to happen. I knew that I’d need a couple different pieces of software to make this work. First, I’d need something that could send me a text message. No problem, my work computer has Microsoft Outlook on it. Second, I’d need something that told me the machine was down. That too wasn’t an issue because, like I said, I have a little programme that already does that. Third, I’d need something to tie them together.

That’s where AutoHotkey comes in.

AutoHotkey is a free scripting language. Using it, you can write some pretty nifty programmes that automate all kinds of things from text replacement to system maintenance to automating tasks in World of Warcraft.

After tinkering around, I came up with 21 lines of code that did the trick. Here’s how-

Step 01: Set up an Internet shortcut using a “mailto:” command.

I created a shortcut on the computer that used a mailto: command just like you’d see in a webpage. I set it up to mail my phone number That’s Verizon’s email gateway to sending text messages. For the subject I put FKI ALERT! and for the body I typed PROBLEM DETECTED WITH THE FKI SELF CHECKIN! I saved the shortcut and, since it was a mailto: shortcut, Windows immediately associated it with Outlook. So if you double click the shortcut, Windows launches an Outlook composer with everything already filled in. All you have to do is send it.

Step 02: Set up a trigger within the code.

My programme works on a very simple workflow. It starts out by looking for the window that pops up when the machine goes down. Normally the little app monitoring the FKI just sits in the system tray and you’ll not see its window. However, when anything goes awry, that window comes up and that’s the only time it comes up. It never appears without cause.

That window is the trigger.

The little app I wrote does nothing but look for that window and, if it doesn’t see it, it goes to sleep for five minutes. No reason to have it check too often and waste processor cycles. Five minutes is fine. So that’s it. It scans the desktop, looks for the window, and if it’s not there it goes to sleep because all is well.

However, if the window is there, the rest of the programme kicks into gear. Like Visual Basic, you can use AutoHotkey to “send keys” just like you would if you were typing. When the window is detected, it calls up that Outlook shortcut. It waits five seconds to give the computer ample time to respond. Then it sends the key combination “Alt S” because that’s the keyboard shortcut used to send an e-mail in Outlook. Then it waits another five seconds to allow processing.

Then my little programme terminates, which brings us to-

Step 03: Fixing the problem

After the e-mail goes out, my programme exits itself. Why? Because the window it’s looking for will not go away until you fix whatever is wrong with the machine. In other words, you have to come in, fix the machine, close out the window, and re-launch my programme. It’s kind of like a grenade, it’s only useful when it goes off but, once it does, that’s all there is. As an added benefit, it won’t keep texting me. I get a text and, depending on the time of day or night, I can go in and fix it if I need to. So while I may just ignore a text coming in on Sunday night at 10pm, I will not ignore the one coming in on Sunday morning at 9am.

So far, it’s been a pretty reliable bit of coding. Then again, in 21 lines (I’m not counting the remarks at the beginning.) there’s not much to screw up. While I’m not a great programmer, everything I do is open source. If your library has a similar machine with a similar problem. I’ve pasted the code below or you can get it from a Google Doc.

; FKI Alert by Daniel Messer
; This programme monitors a computer for the FKI Alert window. When the window is detected
; this programme will call upon an e-mail shortcut to call for help. Ideally, this email
; shortcut should be directed toward an SMS address, but any email address should work.
Loop {
ProcessNameSearch = javaw.exe
; DetectHiddenWindows, on ; Currently commented out because I don’t think I WANT to find hidden windows.
WinGet, id, list,,, Program Manager ; Get all windows for the entire system.
Loop, %id%
StringTrimRight, this_id, id%a_index%, 0
WinGet, this_process, ProcessName, ahk_id %this_id%
if this_process = %ProcessNameSearch%
WinGetTitle, this_title, ahk_id %this_id%
Sleep, 5000
Run f:\FKI_ALERT.url
Sleep, 5000
Send !s
Sleep, 1000
Sleep, 300000

*So I got some pretty decent response on this article, and I have more than just a couple of items to share. They’re not all as involved as this one, but hey, if it helps someone out, then I’ll write about it.