Wednesday, May 5, 2010

Do you want to automate a process?

Sometimes we have to do a same set of things manually everyday. Personally I felt some processes are really tedious, so it is really inefficient to do them manually. There's a solution if we can spend some time on coding. To automate a process we normally use scripting languages, eg: shell scripting, AutoIt etc. In this post I will focus on AutoIt scripting language, which I got to know from a friend of mine.

AutoIt is a freeware scripting language which is mainly useful in automating Windows GUIs (it can use for general purpose scripting as well.). You can download AutoIt from here. I suggest you to download the full installation package since there are some other tools (such as AutoIt Window Info tool) other than the editor, which I found very useful.

You can find AutoIt documentation from here. It has nicely documented, and some examples in "Tutorials" section which is really useful to learn AutoIt. List of functions in AutoIt is listed here.

I used AutoIt to automate some GUIs in my training place (#IFS), and at my home to compile, build, and run Derby from source and also to establish a connection to a database in Derby.

I like this because it is easy to use language, and anyone can get use to it with one full day :).

Here is a script to automate the installation of a software (trial version) called PDFAppraiser:

Run("PDFAppraiser_1_0_1_Install.exe") 
WinWaitActive("Apago PDF Appraiser 1.0.1 Setup", "&Next >")
Send("{ENTER}")
WinWaitActive("Apago PDF Appraiser 1.0.1 Setup", "I &accept the terms in the License Agreement")
Send("!a")
WinWaitActive("Apago PDF Appraiser 1.0.1 Setup", "&Next >")
Send("{ENTER}")
WinWaitActive("Apago PDF Appraiser 1.0.1 Setup", "&Next >")
Send("!n")
WinWaitActive("Apago PDF Appraiser 1.0.1 Setup", "&Install")
Send("!i")
WinWaitActive("Apago PDF Appraiser 1.0.1 Setup", "&Finish")
Send("{ENTER}")

You can download the .exe of the script from here

If you want to test what this script does, place both the exe of the script and pdfAppraiser.exe in the same path, and double click on the exe of the script and watch it runs within seconds.

Explanation of the code:

Run(...) - this method starts the installer
WinWaitActive(title, active button/etc.) - this method waits until the window that titled as title appears with an active button specified. 
Send(...) -Sends a command to proceed to the next window or else you want to do. 

You may wonder how I found these &Next > and other names of the buttons, I found these by using AutoIt Window Info tool, this tool will help you to see what are the names or commands or mnemonics used by the GUI developer.

Hope this post will give you some idea about AutoIt, and believe that you will use this tool.