Automation Mania: How To Use AutoIT!
by Cory Rauch 2005-09-03 Category: Windows-Automation

Have you ever sat doing a task on a computer and asked why this was not automated? In this article Im going to look at the topic of automation and the open source software package AutoIT which can automate things on Windows. Of course there is limitations. The entertainment industries vision of the future where computers run our lives, do our chores, and then eventually go to war with us until we are annihilated has yet to come. But there are still many avenues of automation available on simple task on your desktop today. So lets see read on.

What Is AutoIT?

AutoIT is a BASIC like scripting language / interpreter that can automate running and controlling other programs among other things (The latest version even has a GUI library). For example it contains useful functions for sending keystrokes to an open application. Plus your script can be in turn compiled into a single executable that you can distribute over a bunch of PCs. So we are going to go over some basics on using these functions to automate applications.

You can download it here: http://www.autoitscript.com/

The Basics

Lets look at some basic commands useful in automating things in AutoIT. Of course by no means is this a complete reference guide to all the functionality AutoIT offers, but get you started in simple automation. Ok lets start by look at our first script, a script that opens a web browser and enters a search for autoit.

--- The Script ---
; Runs a web browser and then enters a search statement
Run("C:Program FilesMozilla Firefoxfirefox.exe http://www.yahoo.com")
; Waits for Firefox to start up with following in title bar. Must be exact to work!
WinWaitActive("Yahoo! - Mozilla Firefox")
; Send search keywords
Send("autoit{enter}")

Looking at the above we used only three different commands to do something that might take a lot more in another language. The first command was the easy part; the run function simply launches the target application. Then we used an interesting command that waits for a window to load up with the following title. This enables our script to wait for program its going to automate to be fully loaded and active, so it is ready to actually receive input. Then we used the send command, which can send keystrokes to the target program. In this case our example query autoit and the {enter} part simulates and enter. Other useful characters that simulate keys include: ^ = Ctrl, ! = Alt, + = Shift, # = Win. So we could also after launching this query close FireFox using these additional key characters. For example:

; Runs a web browser and then enters a search statement
Run("C:Program FilesMozilla Firefoxfirefox.exe http://www.yahoo.com")
; Waits for Firefox to start up with following in title bar. Must be exact to work!
WinWaitActive("Yahoo! - Mozilla Firefox")
; Send search keywords
Send("autoit{enter}")
Sleep(1000)
; Exit Firefox
Send("!f")
Send("x")

Looking above we see a new command, sleep, which will just pause execution for n amount of milliseconds (In our example, 1000=1sec). Then we send alt+f or !f to open the file menu and then send x to choose the exit line in the file menu. Piece of cake!

So What Now

So what can you use this for? We went through one example that shows us loading Firefox, searching Yahoo, and closing Firefox. This is not at all very useful, but the concept is. You can use this for example to automate an installation program that cannot be automated any other way. The script in turn can be compiled into an executable and distributed to a bunch of PCs that do not have AutoIT installed, and then the installation can go through automatically. How about auto open-sourcing a Windows PC with a collection of open source programs? Another example of use would be automation of a common task, for example entering your stocks into Yahoo! Finance and getting there results or filling out settings / options not saved in a user un-friendly application you have. AutoIT also has file functions, can use the clipboard, and the environment variables so the option of automating data-entry from one application to another is possible. Theyre by using any one of these methods you can pass data between each application. Example use of this would be sending address data from your Billing application to your Trucking Rater application.

Other ImprovedSource Articles:
How To Synchronize Multiple Folders

Valid HTML 4.01 Transitional