If you need to create a script to automate an applet or an installation that follows a linear or wizard-style workflow, here’s a way of quickly automating it.
This AutoIt script will automate the installation of Opera 9.64 into a custom directory.
MsgBox(64, "Waiting", "Start the Opera installer.")
AutoItSetOption("SendKeyDelay", 200)
Dim $done
$done = False
While Not $done
If WinExists("Opera", "has successfully installed") Then
WinActivate("Opera")
Send("{SPACE}") ; Close the installer
$done = true
ElseIf WinExists("Opera", "Click Install to begin") Then
WinActivate("Opera")
Send("{SPACE}") ; Begin the install
ElseIf WinExists("Opera", "Specify which icons") Then
WinActivate("Opera")
Send("{SPACE}") ; Install default icons
ElseIf WinExists("Opera", "Install Opera") Then
WinActivate("Opera")
Send("{TAB}{SPACE}") ; Open the directory dialog
Send("C:\Opera") ; Change the install directory to C:\Opera
Send("{ENTER}") ; Close the directory dialog
Send("{TAB}{TAB}{TAB}{SPACE}") ; Tab to next button and continue
ElseIf WinExists("Opera", "Custom") Then
WinActivate("Opera")
Send("{SPACE}") ; Disable making Opera the default browser
Send("{TAB}{TAB}") ; Tab to radio buttons
Send("{DOWN}") ; Select custom install
Send("{TAB}{TAB}{TAB}{TAB}{SPACE}") ; Tab back to next button and Continue
ElseIf WinExists("Opera", "agree to this license") Then
WinActivate("Opera")
Send("{SPACE}") ; Select I Accept
ElseIf WinExists("Opera", "Start Setup") Then
WinActivate("Opera")
Send("{SPACE}") ; Select Start Setup
EndIf
WEnd
The basic structure of this style is:
While not done
If screen 1 text exists then
do stuff
Else if screen 2 text exists then
do stuff
Else if final screen text exists then
do stuff
done=true
Each if statement matches with one screen in the program. Each if statement looks for text or an object unique to a screen, and then executes code to handle that particular screen. On the final screen, you break out of the loop to end your script.
The benefits of this style are:
This style is not good for automating programs with non-linear workflows, such as if the same actions repeat or branch with different data.