Saturday, January 26, 2008

Creating simple scripts to automate tasks

Introduction to AutoHotkey

Today, I'll introduce you to a useful scripting program that automates various tasks and assists me in working work faster and more efficiently. I recommend AutoHotkey, a free open source utility for Windows.

What can you do with it? Here are some of its prominent features with which you can:

a) Send keystrokes and mouse clicks

b) Create hot keys for keyboard and mouse

c) Create macros by hand or by using an auto-recorder

d) Expand abbreviations as you type.

e) Automatically correct typos that you often make

f) Convert any script you make into an executable file.

g) Launch programs

It has many other advanced features that may even help you to write an application too, if you wish. I generally use some of the basic features above to create simple scripts. There are libraries of scripts that have already been created, which you can download freely and use.

Here are examples illustrating the use of AutoHotkey features.

First download AutoHotkey and install it.

Let's create a small script to open Notepad and run various commands.

1. Open Windows Explorer and navigate to a folder of your choice.

2. Pull down the File menu and choose New >> AutoHotkey Script (or Text Document).

3. Type a name for the file, ensuring that it ends in .ahk. For example: Test.ahk

4. Right-click the file and choose Edit Script.

5. On a new blank line, type the following (or copy from the line below. All lines beginning with a semi-colon are comment lines.):

------------------------------------------------------------------------------------------------------------

;Use the Windows key + N to launch Notepad

#n::Run Notepad

; If you type "br" without quotes, it will be expanded.

::br::With best regards,{ENTER}Sincerely yours{ENTER}

; Corrects all word endings with "bilty" such as "abilty" to ability"

:?:bilty::bility

;Opens your browser and launches the Honyaku archives when you press the Win key and space.

#space::run http://honyaku-archive.org/search/?q=

;Launches Word when you press the Win key and W.

#W::run winword.exe

;If you have a sequence of operations, you need to end the script using Return.

Return

------------------------------------------------------------------------------------------------------------

If you save the script above as Test.ahk and double click on it, you'll see an icon indicating that the AutoHotkey script is active. You will now be able to do the following:

1. Launch Notepad, open the Honyaku archive and launch MS Word and by pressing the Win key + N, Win Key + space and Win key + W respectively.

2. Type br and have it expanded to:

With best regards,

Sincerely yours

3. Automatically correct all words you have mistakenly typed ending with "bilty" to "bility" (such as abilty -> ability)

Try the above after you have run the Test.ahk script.

You can start with the simple script above keep adding programs/URLs to launch, abbreviations to expand (for instance, a complete template of a letter to client), autocorrect entries (all words that you tend to frequently mistype, such as teh->the) and so on. The more abbreviations and autocorrect entries you add, the lesser you type and the faster your output.

No comments: