Automating your tasks , AutoIT
MsgBox(0, "nothingelz.com", "Hello World!")
The above line is a simple code which shows a Message Box. You just need to open notepad write it down and save it with “.au3” extension, oh I was almost forgetting before that you need to go to http://www.autoitscript.com/autoit3/downloads.shtml and download AutoIt . Unfortunately Windows is only supported operation system.
AutoIt
Well thats it, You created your first AutoIt script. It’s cool, isn’t it ? AutoIT is actually really good for small daily work, you can write small script in AutoIt to do your daily chores
e.g. I use following script everyday morning when I arrive at work :
$answer = MsgBox(4, "nothingelz.com", "Good morning , do you want me to start Visual Studio and SQL Server Management Studio and Firefox ?")
If $answer = 7 Then
MsgBox(0, "nothingelz.com", "OK. c ya!")
Exit
EndIf
Run("C:\Program Files\Mozilla Firefox\firefox.exe") ; firefox huh ?
Run("C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe") ;visual studio
Run("C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\SqlWb.exe") ;sql …
It will ask me whether or not I want it to run Firefox , Visual Studio and Sql Server Management Studio ( these are application that I use everyday at work ) so I do not need to put all of these apps short cut on my desktop and also with one click all of them will be lunched
So lets analyze Above code , in first line I called MsgBox function and put its returns value to variable called $answer. MsgBox accepts three parameters , the first one is called flag which indicate which kind of Message box we want with which kinda buttons combination
| 0 | OK button |
| 1 | OK and Cancel |
| 2 | Abort, Retry, and Ignore |
| 3 | Yes, No, and Cancel |
| 4 | Yes and No |
| 5 | Retry and Cancel |
| 6 ** | Cancel, Try Again, Continue |
This table shows possible value for flag parameter, as you see we used 4 which means that we want Yes/No MsgBox.
The second parameter is Message Box Title and the third one is its message. This function return a value , possible returned values includes :
| Button Pressed | Return Value |
| OK | 1 |
| CANCEL | 2 |
| ABORT | 3 |
| RETRY | 4 |
| IGNORE | 5 |
| YES | 6 |
| NO | 7 |
| TRY AGAIN ** | 10 |
| CONTINUE ** | 11 |
In conditional statement ( If statement ) we check whether user clicked on “No” or not ( in the above table you see that if our return value is 7 , it means user clicked on “No”) . if it was correct we move on next line and show a message to user and then we call “Exit” which exit our script otherwise we skip it and go to the whatever comes after “Endif” .
Then we call Run function, it accepts a path to a file and run it. We just call it three times with path to Firefox , Visual Studio and Sql Server Management Studio.
That’s it, You can change parameter of “Run” and point it to the application which you use. Almost everything else in AutoIt is the same as above code. A Complete Help comes along with AutoIt which contains list of all function and their parameters and return value and purpose of them which is really helpful.
AutoIt is really cool scripting language you can learn it very soon and it has a rich library, full of useful functions.