Task automation and ultimate control over Windows


This post is a continuation on my quest for applications that help me do more by doing less. After choosing and installing an application launcher mentioned in my previous post the next thing I wanted to do is automate a few tasks that I do several times a day. Each one takes a while and throughout the day this adds up. The worst thing is that sometimes another person distracts you from what you were doing and then it takes a while to get back into  it. An interesting coincidence is that while looking for some kind of tool for this I found a very interesting video – a talk called The Productive Programmer by Neal Ford at the Oredev conference. It’s about 50 minutes in length, but I believe it’s a time well spent. He talks about the mechanics of increasing your productivity which, among other things involves learning to let go of the rodent sitting next to your computer that you call a mouse.  After watching this video I went and tried out a few tools mentioned that I didn’t use before and found the Holy Grail of automation software – AutoHotKey. I can’t believe how I managed to live without it all this time. By the way I suggest you download the SciTE4AutoHotKey to help you write the automation scripts. I started simple by defining a few keyboard shortcuts for some actions like running an application or opening a specific webpage.

#IfWinActive, ahk_class MozillaUIWindowClass
^g::Run http://www.google.com
^n::Run http://www.google.com/notebook/
^r::Run http://www.google.com/reader/view/
^m::Run https://mail.google.com/mail/

Then I moved up a little by defining typical text expansions for frequently used commands and redefined keyboard shortcuts for specific applications. There’s still lots to explore, but after browsing through the documentation it seems like there’s no end to what it can do. It hooks into the system at a very low level and you are able to send keystrokes, mouse movement and clicks, read/write to file system and registry, call functions defined in dynamically linked libraries and do lots of other things. One of the first scripts I tried to write was the one that allowed me do build, deploy and open an application that I was working on. It’s pretty simple and maybe it could be implemented better, but it’s still pretty useful.

#c::
File = C:\tomcat-6.0.18\logs\stdout.log
RunWait C:\project\build.bat, C:\project, Hide
FileRead, Contents, C:\project\out
IfInString, Contents, BUILD SUCCESSFUL
{
    FileDelete, C:\tomcat-6.0.18\logs\*
    FileRemoveDir, C:\tomcat-6.0.18\temp, 1
    FileRemoveDir, C:\tomcat-6.0.18\work, 1
    FileRemoveDir, C:\tomcat-6.0.18\webapps\project, 1
    RunWait C:\tomcat-6.0.18\bin\startup.bat, C:\tomcat-6.0.18\bin, Hide
    FileRead, Logcontent, C:\tomcat-6.0.18\logs\stdout.log
    IfInString, Logcontent, project is available for use
    {
        Run http://localhost:8080/project
    }
    else MsgBox Deployment failed
    Logcontent =  ; Free the memory
}
else MsgBox Build failed
Contents =  ; Free the memory
return

You can always do a web search and find some useful scripts for AutoHotKey, a good place to start might be Lifehacker page. If you’re still not sure where this can be useful there are lots of talks of using AutoHotKey inside games to automate some of the actions or use it inside graphic editing applications.